Call us Toll-Free:
1-800-218-1525
Email us

 Sponsors

Logs referer IP Hostname time and browser type to MySQL db

Code Wizard, 12-30-2006



Script Note:
This script needs a MySQL database to work. You'll need to create a database on the server named stats. In that database, you'll need to create a table named browser. In the browser table, make a field named browser. Make a table named date, and make a field named date on that table. Make a table named host, and make a field named host on that table. Make a table named refer, and make a field named referer on that table. put this code on any page that you want. It will log stats.

To the code!!!


<?
$connection = mysql_connect("localhost","root","password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db(stats) or die ("Unable to select requested database");

$browser = $HTTP_USER_AGENT;
mysql_query ("INSERT INTO browser (browser) VALUES ('$browser')");

$date = date("F jS Y, h:iA");
mysql_query ("INSERT INTO date (date) VALUES ('$date')");

if ($REMOTE_HOST == "") {
$host = $REMOTE_ADDR;
}
else {
$host = $REMOTE_HOST;
}
mysql_query ("INSERT INTO host (host) VALUES ('$host')");


if( empty( $HTTP_REFERER ) or '' == $HTTP_REFERER ) {
$HTTP_REFERER = 'No Referer';
}
mysql_query ("INSERT INTO referer (referer) VALUES ('$HTTP_REFERER')");
mysql_close($connection);
?>


Easy enough. If this doesn't work for you, let me know becaue I probably made a typo somewhere in it.
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions