Page 1 of 1

Checking to see if an IP is in the log.

Posted: Sun Sep 17, 2006 10:16 pm
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.

Posted: Sun Sep 17, 2006 10:19 pm
by feyd
strpos() potentially, although my recommendation may change depending on how you've built the file.

Posted: Mon Sep 18, 2006 12:46 am
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...

Posted: Mon Sep 18, 2006 3:42 am
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.

Posted: Mon Sep 18, 2006 4:13 am
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.

Posted: Mon Sep 18, 2006 4:01 pm
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.

Posted: Mon Sep 18, 2006 4:04 pm
by feyd
It's not even remotely possible to fetch a MAC address. That information isn't sent in browser requests.

Posted: Mon Sep 18, 2006 4:24 pm
by toasty2
Ah, ok.