Mega Code Archive

 
Categories / Php / Statistics and Counters
 

Client info logger

1st create ONE table (not four) as follows:- CREATE TABLE statinfo ( browser text NOT NULL, date text NOT NULL, host text NOT NULL, referer text NOT NULL ); Then in the php3 file use the following code to populate it. <? $connection = mysql_connect("localhost","login_name","password") or die ("Unable to connect to MySQL server."); $db = mysql_select_db(YOUR_DATABASE_NAME) or die ("Unable to select requested database"); $browser = $HTTP_USER_AGENT; $date = date("F jS Y, h:iA"); 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); ?>