Jump to content

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

  • Have a table that contains the fields: ip (char), hits (int), last_visit (datetime)

 

IPv4 addresses are unsigned 32-bit integers, so you should store them as unsigned ints, not as chars.

Note: if you use the ip2long function it will return a signed int, not unsigned.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.