IP blocking

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
FlasherJau
Forum Newbie
Posts: 4
Joined: Fri May 03, 2002 9:41 pm

IP blocking

Post 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>
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Are you using PHP to send the email out?
User avatar
toon
Forum Newbie
Posts: 1
Joined: Fri May 24, 2002 8:12 am
Location: Ghent, Belgium, Europe

You can try this

Post 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
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

JAVA != Javascript!
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post 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; ?>
Post Reply