Forum Moderators: coopster

Message Too Old, No Replies

Count My Own Visits

Skewed webstats...

         

sitemaker

9:45 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



Hi all,

I've got a problem with my basic webstats at the moment in that I'm making a lot of updates to the site all the time, for which I'm refreshing the pages all the time. I can't keep track of how many times I view my own pages, and my host can't discount my own visits, so this is something I need to do to get an accurate picture of my visitors.

I envisage a bit of PHP at the top of each page that will get the visitor IP, check to see if it's the same as mine, and if so write the date in a text file.

Am I on the right track with this...

PHP Code:
<?
$domain = GetHostByName($REMOTE_ADDR);
if($REMOTE_ADDR == 12.3.45.678){
$date = $_POST['?'];
$filename = "myiplog.txt";
$content = "$date\n";
$fp = fopen($filename, "a");
$fw = fwrite( $fp, $content );
fclose( $fp );
} else {}
?>

I understand PHP has various date functions but I'm a bit stumped on how to implement this into the $_POST[]; statement. Also, is it okay to simply leave the else tags completely empty?

Also, if there is a better way to do what I want - for example actually counting my hits instead of just listing them - please enlighten me.

Thanks

lobo235

10:55 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



It looks like what you have will work ok except for the part where you are setting the date. I would replace that line with something like:

$date = date("F j, Y, g:i a")."\n";

That will give you the current date in a formatted string. For example: March 10, 2001, 5:16 pm

If it were my script I would try to avoid using the IP address unless you have a dedicated IP that will never change. Otherwise, you will have to update the script everytime your IP changes. I would try to set a cookie on my machines that would identify them from the rest of the site visitors. You could write a script that would set the cookie for you and then keep it in a place where visitors will never see it. Then, each time one of your machines that has the cookie visits the page you could tally them up by date like you are doing or just do a running total.