Page 1 of 1

IP blocking

Posted: Sun May 19, 2002 2:39 am
by FlasherJau
Hi,

Any help on this would be greatly appreciated.

Problem, have mail form that runs on php.
However I have this idiot that has taken it apon
itself to send me about 50 emails a day.
I have the IP & as it is coming from China I figure
I want to block to entire IP range. The script below is running
but it is not blocking this fool all the time.

Any ideas how to block this ratbag out?

Code: Select all

<script language="javascript">
var ip = '<!--#echo var="REMOTE_ADDR"-->'
if (ip == '61.154.*.*') &#123; 
alert("STOP! You are viewing this page from an IP address that is not allowed!");
alert("You really need to get a life!");
if (confirm("Do you want to leave peacefully? Or will I have to help you?"))
&#123;location.href="http://www.loser.com" &#125; else &#123; ("OK you choose I don't care! Bye bye! Don't come back!"); &#123;location.href="http://www.loser.com" &#125;&#125; &#125; 
</script>

Posted: Sun May 19, 2002 8:57 am
by jason
Are you using PHP to send the email out?

You can try this

Posted: Fri May 24, 2002 8:12 am
by toon
Since JAVA is a client side programming language, this means that it is run on this guy's machine. It is easy for this guy to prevent JAVA running on his machine. It is better to implement such a code in PHP, which is run on your server and which cannot be turned off that easily.
I suggest you put something like this at the top of you page (before your html - code or the header function won't work):

<?php
$ip_string = "$REMOTE_ADDR";
if ((substr($ip_string,0,7) == "61.154.") OR !(isset($REMOTE_ADDR)))
header( "Location: http://www.google.com" );
;
?>


this will send anyone from the IP-range 61.154.*.* or without an IP to google instead of to your site.
Be aware however, that people can also mess with their IP-adresses,
but lets hope your guy doesn't know how.

I am not a 100% sure about the substr-syntax, but I think it is OK

Toon

Posted: Fri May 24, 2002 1:39 pm
by MattF
JAVA != Javascript!

Posted: Fri Jun 07, 2002 12:44 am
by Kriek
Hey here's an idea that I've done before.
Instead of blocking his IP, why not exclude pages or certain parts of the script based on his IP?

Code: Select all

<?php
$ShoutBan = array("IP Adress to Ban"); 
?>
<?
$ShoutBanString = implode (":", $ShoutBan); 
$Shoutverify = getenv("REMOTE_ADDR"); 
if (strstr($ShoutBanString,$Shoutverify)) &#123; 
print "Sorry you have lost your privileges! This is most likely due to breaking the guidelines and/or rules for this form. If you think this is in error. Please contact me."; 
&#125;
else &#123;
?> 

Place Content you don't want him to see here. This could be whole PHP pages if it's placed at the top or just parts of a script like the "Submit" button. There are other ways, but this works for me. 

Make sure this last part is intact. 

<? &#125; ?>