Click to See Complete Forum and Search --> : Multiple IP banning


flambor
06-14-2003, 02:08 PM
Does anybody know of a good IP banning javascript that can ban multiple IPs and works in IE and Netscape?

brendandonhue
06-14-2003, 02:19 PM
You can't ban IPs in javascript. JS can not detect a users IP.

diamonds
06-14-2003, 04:54 PM
!!!WARNING!!!WARNING!!!

I think you can detect a users IP, but if you want to use it to ban a users IP, do NOT use javascript to solve this problem. Instead, use a server-side language, like perl, PHP, asp, .shtml , but [I think :rolleyes: ]a .hactass file would do the job, as well.

why not javascript?
people could just disable javascript in their browsers!

brendandonhue
06-14-2003, 04:59 PM
No you can not detect a users IP address using javascript. Netscape does have a way-but its actually using java that is controlled by javascript.

flambor
06-15-2003, 04:25 AM
Where can I find a script that will do the job then?

brendandonhue
06-15-2003, 08:31 AM
What server side languages do you have access to?

Zero
06-15-2003, 08:52 AM
I think this may work. It does in IE, I'm not sure about Netscape. :)

<SCRIPT LANGUAGE="JavaScript">
function ban(){
alert("You are banned from this site!!!");
location.replace("URL"); //URL of the page where they are kicked to
}
var ip = '172.137.3.246';
window.status = "Your IP Address is : " + ip;
if ((ip == "111.11.111.111") || (ip == "222.22.222.222") || (ip == "333.333.333.333"))
{
// Just add the ip address of people who you want to ban to
// the above "if" statement as shown above
ban();
// BE SURE YOU SAVE THE WEBPAGE AS ".shtml", just
// change it from ".html" or ".htm" to ".shtml"
}
</script>

flambor
06-17-2003, 12:42 PM
what is the 'var ip' in that script? do i have to change it?

brendandonhue
06-17-2003, 12:48 PM
First of all-no that script doesnt work. You skipped the part about REMOTE_ADDR which is the part that actually detects the IP.
Second-the script is not completely javascript. It requires Server-Side-Includes.

pyro
06-17-2003, 01:52 PM
Yes, as brendandonhue mentioned, the script that Zero provided will do nothing to ban an IP... You need to GET the users IP before you can ban it...

If you have access to PHP, you would do it like this:

<?PHP
#Add this script to the very top of your page, before any other content...
$ip = $_SERVER["REMOTE_ADDR"]; #get the users IP
$banned = array("111.111.111.111","222.222.222.222"); #set up the IPs to ban, separated by commas (,)

foreach ($banned as $ban) { #loop through the array of banned IPs
if ($ip == $ban) {
header("Location:http://www.yourdomain.com/banned.php"); #send banned IPs to banned.php
}
}
?>

EDIT: code edited to provide an array of banned IPs

flambor
06-18-2003, 10:32 AM
does anybody know why this will not work? except for the fact i haven't put my ip in.

ip.shtml (http://homepage.ntlworld.com/michael_naylor/ip.shtml)

brendandonhue
06-18-2003, 10:42 AM
Rereat the thread. That script does not do anything as I said above.

And the PHP isnt working because its an shtml file.
if your server supports PHP, use Pyros script and save it as .php.
If it supports SSI, use this script
http://javascript.internet.com/user-details/ip-filter-2.html

flambor
06-18-2003, 10:48 AM
if i use ssi what do i need to save it as?

brendandonhue
06-18-2003, 10:53 AM
shtml

But make sure your server supports SSI.