hit counter/referrer script
-
I have a PHP/MySQL-based hit counter/referrer script (downloaded from I don’t remember where, unfortunately) that works great with flat files but not with database files. My webhost provides these statistics but not in real time, so I’d like to implement this script on my WP installations. Could anyone more knowledgeable with PHP tell me how to adapt this code for this purpose?
<?php
/*
3C, by Andrew Walton.
Under the GPL, see them for a copy of the license.
*/
//determines the PageId.
if (!empty($_POST[‘Id’])) {
$Id = $_POST[‘Id’];
} elseif (!empty($_GET[‘Id’])) {
$Id = $_GET[‘Id’];
} else {
$Id = 18;
}
$connex = mysql_connect(“localhost”, “username”, “password”);
mysql_select_db(“database”);
$q=”INSERT INTO counter_cal VALUES (‘”.$Id.
“‘,'”.$_SERVER[‘REMOTE_ADDR’].
“‘,'”.$_SERVER[‘REQUEST_URI’].
“‘,'”.$_SERVER[‘HTTP_REFERER’].
“‘,'”.$_SERVER[‘HTTP_USER_AGENT’].
“‘,'”.date(“m-d-Y”).
“‘,'”.date(“H:m:s”).
“‘,”)”;
$r=mysql_query($q) or die(“ERROR”);
$query=”select count(id) from counter_cal”;
$ret=mysql_query($query);
while($w=mysql_fetch_array($ret)) {
$count=$w[‘count(id)’];
}
echo “You are visitor #{$count}”;
?>
Thanks.
The topic ‘hit counter/referrer script’ is closed to new replies.