Login Register






PHP Unique Visitor IP Grabber filter_list
Author
Message
PHP Unique Visitor IP Grabber #1
I see there's quite a few IP grabbers, but have yet to come across a "unique visitor" one. Since I'm new to the forums, and thought I'd share something, so here it is.

PHP Code:
<?php $BlockedIPs = Array('Your IP here'); $Unique = 1; $Time = Date("g:i a") . ' on ' . Date("m/d/Y"); $IP = $_SERVER['REMOTE_ADDR']; $Port = $_SERVER['REMOTE_PORT']; $Data = "Received at $Time\nIP Address: $IP\nAccessed through Port $Port\nhttp://www.ip-tracker.org/locator/ip-lookup.php?ip=$IP\n\n"; $Log = 'ip_log.txt'; $Contents = File_Get_Contents($Log); If($Unique == 1){ If(!strpos($Contents, $IP)){ If(!In_Array($IP, $BlockedIPs)){ $File = FOpen($Log, 'a+'); FWrite($File, $Data); FClose($File); } } Else{ Die('An unexpected error has occurred.'); } } ElseIf($Unique == 0){ $File = FOpen($Log, 'a+'); FWrite($File, $Data); FClose($File); } ?>

It's somewhat simple, but it does the trick. I tried to shorten that as best as I could, but hope everyone likes it.

Update:
I've updated the "If(!strpos" statement, as it wasn't functional.
(This post was last modified: 10-21-2013, 07:11 PM by rektosaurus.)
[Image: siggy.php?uid=66857]

Reply

RE: PHP Unique Visitor IP Grabber #2
Unique visitor counters are not uncommon. And they arent difficult to code.

Also, it would be much more efficient to use an sql database. sqlite even. And i would add the ability to count the number of times a unique vistor, visits.

Reply

RE: PHP Unique Visitor IP Grabber #3
(10-19-2013, 02:11 AM)Geoff Wrote: Unique visitor counters are not uncommon. And they arent difficult to code.

Also, it would be much more efficient to use an sql database. sqlite even. And i would add the ability to count the number of times a unique vistor, visits.

Will do, thank you for the feedback, and tips.
[Image: siggy.php?uid=66857]

Reply

RE: PHP Unique Visitor IP Grabber #4
(11-17-2013, 02:12 PM)snooper Wrote: They are easy to code, and it would be faster+better if u used sql Smile

Technically not faster, as depending on how your database fills up, the requests could take more time, while the current code just queries a text file, and can pull by IP through the whole list. I've converted my code to a database though.
[Image: siggy.php?uid=66857]

Reply

RE: PHP Unique Visitor IP Grabber #5
(11-17-2013, 02:12 PM)snooper Wrote: They are easy to code, and it would be faster+better if u used sql Smile

Technically not faster, as depending on how your database fills up, the requests could take more time, while the current code just queries a text file, and can pull by IP through the whole list. I've converted my code to a database though.
[Image: siggy.php?uid=66857]

Reply

RE: PHP Unique Visitor IP Grabber #6
(11-25-2013, 06:45 PM)Crime Wrote:
(11-17-2013, 02:12 PM)snooper Wrote: They are easy to code, and it would be faster+better if u used sql Smile

Technically not faster, as depending on how your database fills up, the requests could take more time, while the current code just queries a text file, and can pull by IP through the whole list. I've converted my code to a database though.

I would argue that though that depending on the implementation of your file search that could also take longer. Both could be optimized or poorly coded. Also depends on size. On an app of this size you probably arent going to get thousands of IP's in a txt file so SQL would probably have a moderately larger overhead, which is why i suggested sqlite.

Allows for a much more refined storage of information without as much of the server overhead. its like opening a text file except with an easier way of storing more relevant information.

Reply

RE: PHP Unique Visitor IP Grabber #7
(11-25-2013, 06:45 PM)Crime Wrote:
(11-17-2013, 02:12 PM)snooper Wrote: They are easy to code, and it would be faster+better if u used sql Smile

Technically not faster, as depending on how your database fills up, the requests could take more time, while the current code just queries a text file, and can pull by IP through the whole list. I've converted my code to a database though.

I would argue that though that depending on the implementation of your file search that could also take longer. Both could be optimized or poorly coded. Also depends on size. On an app of this size you probably arent going to get thousands of IP's in a txt file so SQL would probably have a moderately larger overhead, which is why i suggested sqlite.

Allows for a much more refined storage of information without as much of the server overhead. its like opening a text file except with an easier way of storing more relevant information.

Reply