Page 1 of 1

Hit Counter

Posted: Tue Feb 24, 2004 6:04 pm
by davy2001
Hi,
i have made a hit counter in flash and it uses php to work. i got everything to work but now im trying to make it better so that it logs the users visited and i a trying to make it so that it doesnt log my ip address and and a few more addresses. here is my code so far:

Code: Select all

<?php

$count = file_get_contents("count.txt");

$count = explode("=", $count);
$count[1] = $count[1]+1;

$ipad1 = 127.0.0.0;
$ipad2 = 192.168.1.1;
$ipad3 = localhost;

$ip = $_SERVER['REMOTE_ADDR'];
$date = date("n-j-Y, g:i:sa");
if ($ip == "$ipad[]"){
echo "";
} else {
$file = fopen("count.txt", "w+");
fwrite($file, "count=".$count[1]);
fclose($file);

$filename = 'logs/weblog.html';
$fp = fopen($filename, "a");
$string = "
<tr>
<td bgcolor=white><font face=arial size=1 color=black>
<center>$date</td>
<td bgcolor=white><font face=arial size=1 color=black>
<center>$ip</td>
</tr>";
$write = fputs($fp, $string);
fclose($fp);

print "count=".$count[1];
}
?>

it should save the log to weblog.html.

Dave
?>

Posted: Tue Feb 24, 2004 7:33 pm
by John Cartwright
Errors? What's not working?

Posted: Tue Feb 24, 2004 7:49 pm
by davy2001
i tested it on a dialup machine and it didnt change the number in the text file :s

i want it to allow other users appart from the ip addresses in the code to work the counteer. this is bcos im always viewing my website and updating it. all the hits will be me.

Dave

Posted: Tue Feb 24, 2004 10:21 pm
by John Cartwright
Not too sure but try that

Code: Select all

<?php


$count = file_get_contents("count.txt"); 

$count = explode("=", $count); 
$count[1] = $count[1]+1; 

$ips = array("127.0.0.0","192.168.1.1","localhost");
$ip = $_SERVER['REMOTE_ADDR']; 
$date = date("n-j-Y, g:i:sa"); 
if ($ip != "$ips[]"){  
$file = fopen("count.txt", "w+"); 
fwrite($file, "count=".$count[1]); 
fclose($file); 

$filename = 'logs/weblog.html'; 
$fp = fopen($filename, "a"); 
$string = " 
<tr> 
<td bgcolor=white><font face=arial size=1 color=black> 
<center>$date</td> 
<td bgcolor=white><font face=arial size=1 color=black> 
<center>$ip</td> 
</tr>"; 
$write = fputs($fp, $string); 
fclose($fp); 

print "count=".$count[1]; 
} 
 

?>