Top

IP Block


Javascript Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  Aug 23, 2009
Last Updated  Aug 23, 2009
Tags  block  ip 

Introduction

Use this script to block certain IPs from your webpage, by redirecting them to another site. Note that your web server must have SSI enabled (most Linux servers do), with the page using the correct extension (ie: .shtml) in order for this script to work. Furthermore, since this script relies on JavaScript to block the user (by redirecting the person to another site), if he/she disables JavaScript in the browser, the script will become futile.


Grab the Code

<script type="text/javascript"
 
//Enter list of banned ips, each separated with a comma:
var bannedips=["23.23.23.23", "11.11.11.11"]
 
var ip = '<!--#echo var="REMOTE_ADDR"-->'
 
var handleips=bannedips.join("|")
handleips=new RegExp(handleips, "i")
 
if (ip.search(handleips)!=-1){ 
alert("Your IP has been banned from this site. Redirecting...")
window.location.replace("http://www.google.com")
}
 
</script>

Comments

  (1)  RSS
jonesy44
Comments: 1,856
 
Javascript Snippet:  IP Block
Posted on Aug 23, 2009 3:11 pm
you should re-write this in PHP, that way the server handles the code execution, there's nothing the client can do to avoid the "block". This is not secure.

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom