Checking to see if an IP is in the log.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Checking to see if an IP is in the log.

Post by toasty2 »

Ok, I have a service where you can only use it once. After using it, it saves your IP to a log and when you attempt to use it again it looks for your IP in the log. This code isnt working, its always restricting people, as long as there's any information in the log.

Code: Select all

if (str_replace($_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_ADDR'], $slog))
{
die("Sorry, only one account per person.");
}
Is there a better way to check if someone's IP is in the log? (That works)
When the log is empty, it works. But not when any information is in it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

strpos() potentially, although my recommendation may change depending on how you've built the file.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

*my ip*??? I have to share it with at least 250 other people that are currently behind the NAT... Which voids the idea of1 ip == 1 person...
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

timvw wrote:*my ip*??? I have to share it with at least 250 other people that are currently behind the NAT... Which voids the idea of1 ip == 1 person...
ereg() would be another possibility.
However, timvw is right - by using this approach you'd exclude quite a lot of people while not being able to prevent users from logging in several times (by using proxies). Cookies might be worth a thought, but they can be deleted / disabled as well. The same is true for local shared objects in flash.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

PHP recommends, as feyd did, strpos().

From php.net/strstr:
Note: If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos() instead.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

I would worry about multiple people using the same IP, except for that my service is very small, and will definately not be widely used. If only I could get people's mac addresses...php needs to add that.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's not even remotely possible to fetch a MAC address. That information isn't sent in browser requests.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

Ah, ok.
Post Reply