Mega Code Archive

 
Categories / Php / Statistics and Counters
 

Logs referer, IP-Hostname, time, and browser type

<? // Hit and visitor counter $connection = mysql_connect($hostName, $userName, $password) or die ("Unable to connect to MySQL server."); $db = mysql_select_db($databaseName) or die ("Unable to select requested database"); $browser = $HTTP_USER_AGENT; $date = date("F jS Y, h:iA"); // Check if the referer is your site if not then add record if (preg_match ("/www.YOUR_DOMAIN.com/i", "$HTTP_REFERER")) { mysql_close($connection); } else { // If you cant resolve domain use IP address if ($REMOTE_HOST == "") { $host = $REMOTE_ADDR; } else { $host = $REMOTE_HOST; } if( empty( $HTTP_REFERER ) or '' == $HTTP_REFERER ) { $HTTP_REFERER = 'No Referer'; } mysql_query ("INSERT INTO statinfo (browser, date, host, referer) VALUES ('$browser','$date','$host','$HTTP_REFERER' )"); mysql_close($connection); } ?>