Need help with limiting my logfile

Discussion in 'PHP' started by GBG, Dec 9, 2008.

  1. #1
    Hello!

    Anyone with a few moments to spare?
    Thing is that i got a snippet that log my visitors, but its getting bigger and bigger and I want to set up a limit for it. I want it be no more than 30 posts/rows, and it should remove the oldest log if visitor 31 comes to the site..

    here's what it looks like today:
      function logfile ()
      {
        global $link_url;
        global $config;
        if ($config['log'] == 1)
        {
          $fp = fopen ('log/logfile.txt', 'a');
          fwrite ($fp, 'IP of User: ' . $_SERVER['REMOTE_ADDR'] . ' - Referrer: ' . $_SERVER['HTTP_REFERER'] . ' - User Agent: ' . $_SERVER['HTTP_USER_AGENT'] . '
    ');
          fclose ($fp);
        }
    
      }
    PHP:
    Regards
     
    GBG, Dec 9, 2008 IP
  2. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Looks redundant to me. Why don't you just keep server access logs?
     
    keyaa, Dec 9, 2008 IP
  3. GBG

    GBG Active Member

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    93
    #3
    I have no good answer to that. I suppose I could do that, keep the access logs. :)

    But just to explain what I was looking for.. The code above logs any user, even if it's visitor 29, 30, 31, 55. What I want is to loop when it reaches 30 log posts.
     
    GBG, Dec 9, 2008 IP
  4. firman01

    firman01 Well-Known Member

    Messages:
    155
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    165
    #4
    before appending the log to the file, you might wanna add severeal things

    1. check if has 30 logs
    2. remove the first log, so only have 29 logs left.
    3. add the log after the last line.
     
    firman01, Dec 9, 2008 IP