Jump to content

Advanced IP logging?


php-n00b

Recommended Posts

What's Up?

 

OK, Now I have the typical IP logging script.

<?php
$logfile= 'Database.html';
$IP = $_SERVER['REMOTE_ADDR'];
$logdetails=  date("F j, Y, g:i a") . ': ' . '<a href=http://dnsstuff.com/tools/city.ch?ip='.$_SERVER['REMOTE_ADDR'].'>'.$_SERVER['REMOTE_ADDR'].'</a>';
$fp = fopen($logfile, "a"); 
fwrite($fp, $logdetails);
fwrite($fp, "<br>");
fclose($fp); 
?> 

 

But I'm expecting lots of visits from the same IP, So instead of adding a new line to the log file for the same IP, Is it possible to over write the last recorded visit, So only the time of that visit is updated?

 

Thanks Bye.

Link to comment
https://forums.phpfreaks.com/topic/184434-advanced-ip-logging/
Share on other sites

Possible, but would be extremely difficult with a flatfile database. You are better off leaving the log there as the time it would take to open the file find the right IP(s) and overwrite them then save the file, other people could have visited the site and your log file is now out of sync and overwrote other IP logs.

 

If you want that functionality I would suggest going with a Relational Database.

Link to comment
https://forums.phpfreaks.com/topic/184434-advanced-ip-logging/#findComment-973580
Share on other sites

premiso is right.  Putting it into a database will be better, allowing you to run queries against it and create reports from it easier.

 

One way you could do it is this.

  • Have a table that contains the fields: ip (char), hits (int), last_visit (datetime)
  • When the visitor loads the page, get the IP address and check to see if it's in the table.
  • If it is in the table, update the row containing the IP address by incrementing the count in 'hits' and updating the 'last_visit' with the new datetime.
  • If it is not in the table, create a new row.

 

This only works if you're only concerned with the last visited datetime only.

Link to comment
https://forums.phpfreaks.com/topic/184434-advanced-ip-logging/#findComment-973587
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.