Fix Redirect Based on 24h Unique IP

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.

$seconds = 86400;
$newtime = time();
$filename = “list.1”;
$url = “
$url2 = “”;
// *** 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));

// *** have you be here less than 24 hours ago ***
   for ($i=0; $i< count($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");
     // *** 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");      
      header("Location: $url");

    } // 	


Sponsor our Newsletter | Privacy Policy | Terms of Service