|
Posted by toedipper on 09/04/05 15:17
Hello,
PHP and MYSql
I have the code below which logs a visitor to my site via logging the
session id and other details in a table. I only want to count a visit
once so I have a check to see if the session id is in the table already
then don't log it. I don't want an entry in the event of a surfer
hitting refresh on the browser or revisitng the page during a session.
However, not only is it logging the first initial visit during the
session but it is also logging the second. It does not log the third
visit on.
Any ideas?
thanks in advance,
rg www.pocketpcheaven.com
<?
session_start();
$valid = "yes";
$_SESSION[valid] = $valid;
include ('Connections/local.php');
// Log the visit first
$sessionid = session_id();
$ipaddress = GetHostByName($REMOTE_ADDR);
$agent = getenv("HTTP_USER_AGENT");
// check to see if running ie
if (preg_match("/PPC/i", "$agent")) {
$browser = "PPCIE";
}
//check to see if running Firefox
else if (preg_match("/Firefox/i", "$agent")) {
$browser = "Firefox";
}
// check to see if running opera
else if (preg_match("/Opera/i", "$agent")) {
$browser = "Opera";
}
// check to see if running pocket pc browser
else if (preg_match("/MSIE/i", "$agent")) {
$browser = "IE";
}
// if anything else just display the browser string
else {
$browser = $agent;
}
// but.. b4 that have a look to see if session id exist already, we only
want to log new users
mysql_select_db($database_local, $local);
$sqlchecksession = "SELECT sessionid from visitors where sessionid =
'$sessionid'";
$result = @mysql_query($sqlchecksession, $local) or die(mysql_error());
$thenum = mysql_num_rows($result);
if ($thenum <=1 ) {
// if ok and not exist already then log the visit
mysql_select_db($database_local, $local);
$query_rslogvisit = "INSERT INTO visitors (sessionid, ipaddress,
browser, visitdate, visittime) VALUES ('$sessionid', '$ipaddress',
'$browser', current_date(), current_time())";
$result = mysql_query($query_rslogvisit) or die(mysql_error());
}
[Back to original message]
|