Heres the code I need fixed, just need to log ip in file or sql and if time > 24h redirect to $url2 if not redirect to $url1
The problem I have is it sets all ips in list.1 to current time everytime a new ip is added to list.1 would like it to search the file before adding it, basically direct to $url once every 24h and reset after 24h is what I want to do.
[php]
$seconds = 86400;
$newtime = time();
$filename = “list.1”;
$url = “http://www.google.com”
$url2 = “http://www.msn.com”;
// *** get IP address ***
if ($HTTP_X_FORWARDED_FOR == “”) {
$ip = getenv(REMOTE_ADDR);
}else {
$ip = getenv(HTTP_X_FORWARDED_FOR);
}
// open and read data from ‘ip’ file
$fp = fopen($filename,‘r’);
while (!feof($fp)) {
$ips[] = chop(fgets($fp,4096));
}
fclose($fp);
// *** have you be here less than 24 hours ago ***
for ($i=0; $i< count($ips); $i++){
$ips[$i]=trim($ips[$i]);
$ips[$i] = explode('|', $ips[$i]);
if (($ips[$i][0]==$ip) && ($newtime-$ips[$i][1]< $seconds)){
$foundme= true;
}
}
if ($foundme){
//echo "<$font_small>You been here within 24h</font>";
header("Location: $url2");
die();
}else{
// *** open 'ip' file to write data ***
$fp= fopen($filename, 'w');
fputs($fp, "$ip|$newtime\n");
//echo "<$font_small>Your ip has been recorded </font>";
for ($i=0; $i< count($ips); $i++){
if ($newtime-$ips[$i][1]< $seconds){
fputs($fp, $ips[$i][0]."|".$newtime."\n");
}
}
fclose($fp);
header("Location: $url");
exit;
} //
[/php]