Forum Moderators: open

Message Too Old, No Replies

blocking range of ip address with javascript

         

script

11:05 am on Mar 25, 2010 (gmt 0)

10+ Year Member



Plz confirm if the following code is ok

<!--#if expr="${REMOTE_ADDR} = /115.117.210.186|^115.184|117.197.25.252/" -->
<script language="javascript">
alert("Your ip has been banned from this site");
{location.href="http://www.google.com" }
</script>
<!--#endif -->

whoisgregg

2:41 pm on Mar 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, script!

One change to the code... Don't wrap the location.href line in curly braces. Just put it on it's own line (preferably with a semicolon at the end).

location.href="http://www.google.com";

That said, this concept will work, but it's also very easy for the user to avoid this by simply disabling JavaScript in their browser. You'd be much better off doing this server side with PHP (or whatever server-side language you have access to).

script

11:27 am on Mar 26, 2010 (gmt 0)

10+ Year Member



The code is working fine, except that its blocking me too. Please help.

daveVk

11:00 am on Mar 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!--#if expr="${REMOTE_ADDR} = /115.117.210.186|^115.184|117.197.25.252/" -->

This is an instruction to your server (asp maybe?), are you sure the server is set up correctly ?

Disable JavaScript in your browser and view the page source you get, if it contains the above line the server is not set up correctly.

incrediBILL

11:23 am on Mar 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your code sample is in pattern matching mode and DOTS mean match any character, therefore they must be escaped.

The correct string should be:

<!--#if expr="$REMOTE_ADDR = /115\.117\.210\.186|115\.184\..*|117\.197\.25\.252/" -->