help with log.txt

Discussion in 'PHP' started by DjZoC, May 29, 2010.

  1. #1
    Hello there, this is the code

    <?php
    
     $iplogfile = "log.txt";
     $fp = fopen($iplogfile, "a");
    
     if ($fp)
     {
      fputs($fp, $_SERVER["REMOTE_ADDR"]." \n");
      fclose($fp);
     }
    
    ?>
    PHP:
    Can someone help me how i can make if the $_SERVER["REMOTE_ADDR"] is aready on log.txt to dont add again the ip on log.txt

    Thanks
     
    DjZoC, May 29, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    <?php
    
     $ip_log_file_name = "log.txt";
     $ip_array = file($ip_log_file_name);
     $fp = fopen($ip_log_file_name, "a");
    
     if ($fp && !in_array($_SERVER["REMOTE_ADDR"]." \n", $ip_array))
     {
      fputs($fp, $_SERVER["REMOTE_ADDR"]." \n");
      fclose($fp);
     }
    
    ?>
    PHP:
     
    danx10, May 29, 2010 IP
  3. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    works thanks
     
    DjZoC, May 29, 2010 IP