Hello. Im trying to make a hit counter that logs
ip,browser, date and time. It works ok, except that I would
like it to wait logging hits from last IP for one hour.
How do I modify my script to do this ? Below is my script :
<?php
# Defines variables
$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$date = date('d.m.Y');
$time = date('H.i.s');
# Open file
$file = file('hits.txt');
# Print out to screen
foreach ($file as $line) {
print "$line<br>";
}
# Adds one step for each entry
$count = count($file) + 1;
# Exclude ip-addresses that already exists in the text file
if(in_array($ip." :: ".$browser." :: ".$date." :: ".$time."\n",$file) and (time() + (3600))>$time) {
# Do nothing
}
else {
# Writes to file
$write = fopen('hits.txt', 'a');
fwrite($write, $ip." :: ".$browser." :: ".$date." :: ".$time."\n");
fclose($write);
}
?>