Page 1 of 1
Need help with IP detecting
Posted: Sat Apr 03, 2010 7:54 am
by Chinclub
I have a pet classifieds script that I wrote in PHP and now that it is high on the search engines I am getting a ton of SPAM ads. I notice that most of the new members who post the spam come from IP addresses starting with either 119. or 122. I want to place a line of script in the register.php that will flag any new member coming from an IP address starting with those numbers. I can't seem to figure out how to do it with my limited PHP knowledge.
I was hoping something like would work:
Code: Select all
$ip = $_SERVER['REMOTE_ADDR'];
if ($ip = '119.%'){
print " Your account is flagged please contact the admin";}
else{
I tried it with my own IP address and it didn't work. Does anyone have a suggestion? I have to find a way to keep these people out of my site. Its becoming a huge problem

Re: Need help with IP detecting
Posted: Sat Apr 03, 2010 9:31 am
by samwho
You could try:
Code: Select all
$ip = $_SERVER['REMOTE_ADDR'];
if (substr($ip,0,3) == '119' || substr($ip,0,3) == '122'){
print " Your account is flagged please contact the admin";}
else{
}
Also, don't know if you noticed, but your operator in your if statement was wrong. You used the assignment ("=") operator instead of the comparison ("==") operator

Re: Need help with IP detecting
Posted: Sat Apr 03, 2010 11:05 am
by Chinclub
That seems to work great!! Thanks.
Re: Need help with IP detecting
Posted: Sat Apr 03, 2010 11:12 am
by samwho
You need to be careful when basing ban systems on IP addresses, though, especially ones as general as blocking based on the first 3 digits... I don't know a huge amount about IP addresses but I can imagine blocking all addresses beginning with a certain 3 digits to be a little risky... Anyone able to give more insight into this?

Re: Need help with IP detecting
Posted: Sat Apr 03, 2010 7:06 pm
by Chinclub
Do you mean by accidentally blocking valid visitors? The best I can tell from IP lookups it seems those first three digits specify a foreign country. Since my classifieds are targeting people in the USA and Canada I'm not concerned with this problem. However, I did plan on having a contact form for anyone who gets blocked by the IP catcher and still feels they want to join. Then I can create those accounts on a case by case basis. I am hoping these spam ad placers won't waste there time when they see I am serious about not placing their ads.
Is there another problem I am not thinking of?

Re: Need help with IP detecting
Posted: Sat Apr 03, 2010 9:44 pm
by samwho
No, that was my main concern
