View Full Version : Block an IP (not MySpace)
HI I tried following instructions from this thread:
http://forum.statcounter.com/vb/showthread.php?t=16690&highlight=myspace
but I am having a problem following. I am new to HTML code and don't know all the rules.
I am trying to block someone from a personal homepage - not myspace. I want them to be redirected elsewhere. I used this code highlighted in blue to show you. I used it EXACTLY like this, spaces and all. Each line exactly the way it appears. Is this correct? :confused:
<script language="javascript" type="text/javascript">
<!--
var ip = '<!--#echo var="REMOTE_ADDR"-->';
if (ip == "xxx.xxx.xxx.xxx") {
alert("You are visiting this site from a blocked IP address " +ip);
window.location="http://www.aol.com"
}
// -->
</script>
I attempted to block my own IP first to see if it would work. Nothing. I am using Frontpage and I placed the code up top under the <body> section. Above that I have the head and title sections. There is no template, just what I made with tables and text in the "normal" view. I also have the stat counter (invisible) on the same page. The code is inserted near the bottom and it is working perfectly for me. Any guidance would be very much appreciated. :-D
~Dana~
webado
01-05-2006, 02:07 AM
That script goes after the <head> tag, and before the </head> tag. Not in the body section.
Make sure you're not using design mode or layout mode. It has to be code view mode, source code mode or html mode - whatever it may be called in Frontpage.
But another problem you'll have is that this script requires that the page where you use it has to be suffixed by .shtml not .html , because it uses a SSI (server side include) directive. The server only interprets that at all if the file is suffixed by .shtml .
Thanks so much! I will try that out. I hope I do it right :)
I have tried this out on my IP, and it works as far as blocking goes, but rather than getting redirected to the designated webpage, I get this message:
Directory Listing Denied
This Virtual Directory does not allow contents to be listed.
Is there something I am doing wrong or is there another way to have the blocked user redirected to another website - for example, the online dictionary definition of "stalker"? :-P Thanks for your help!
Another question, will statcounter log whether or not this person continues to try to access my page if they are blocked?
webado
01-10-2006, 11:12 PM
I have tried this out on my IP, and it works as far as blocking goes, but rather than getting redirected to the designated webpage, I get this message:
Directory Listing Denied
This Virtual Directory does not allow contents to be listed.
Is there something I am doing wrong or is there another way to have the blocked user redirected to another website - for example, the online dictionary definition of "stalker"? :-P Thanks for your help!
Another question, will statcounter log whether or not this person continues to try to access my page if they are blocked?
Well, where are you redirecting that visitor from the banned ip address? It has to be a proper url somewhere, the way you'd use it in the address bar of the browser (with http:// in front).
That visit won't get logged actually since the script happens before the rest of the page loads. You cannot place that script elsewhere though , as it will give an error, redirection has to happen before anything of the page is output by html.
LOL okay I am literally trying to redirect the deranged visitor to this site: http://www.urbandictionary.com/define.php?term=Mental
Can I just paste it in there? Do I need to add a hyperlink to that?
Thanks so much for your help!!!
webado
01-10-2006, 11:43 PM
It has to simply be used in place of the aol url from the earlier example.
<script language="javascript" type="text/javascript">
<!--
var ip = '<!--#echo var="REMOTE_ADDR"-->';
if (ip == "xxx.xxx.xxx.xxx") {
alert("You are visiting this site from a blocked IP address " +ip);
window.location="http://www.urbandictionary.com/define.php?term=Mental";
}
// -->
</script>
Of course this won't ever work for a visitor with a javascript disabled browser.
And dont' remember you need to save yoru page as .shtml as it is using an SSI construct.
Chrisoc, thank you so much for your help! I really appreciate it!!! :D
Okay, when trying it out yesterday afternoon, I saved as a .shtml and blocked my own IP. I was blocked, just not redirected. That is when I wrote back in the forum asking if I was doing something wrong because I was not getting redirected to the designated site. I wondered if I had the spacing messed up. I pasted the new address right over the AOL address from the sample. Can you think of anything crucial that would prevent that redirection from working? From the things you have mentioned, I believe I have gotten them taken care of. BTW, have you ever tried to block & redirect anyone?
According to statcounter, the visitor has Java enabled. I also have Java enabled and pretty much have the same set up as the visitor that I want to block and send elsewhere.
When I blocked myself, I did not get the message in quotes on the code. Is this "You are visiting this site from a blocked IP address " supposed to appear as well? Before I block the actual person, I am hoping to try it out and see exactly what they will see.
webado
01-11-2006, 01:02 PM
I don't know how you actually did it.
Here's what I'm doing (and make sure the IP address you are testing with is correct at that moment - to be used instead of 255.255.255.255 which is below):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="EN">
<head>
<title>To ban or not to ban</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
var ip = '<!--#echo var="REMOTE_ADDR"-->';
if (ip =='255.255.255.255') {
alert("You are visiting this site from a blocked IP address " +ip);
window.location="http://www.urbandictionary.com/define.php?term=Mental";
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<p> </p>
<p align="center"><b>Page content here.</b></p>
</body>
</html>
For the ip address substitute the one you have at the moment you are testing.
Also for the page to redirect to use a url of your own, either on your website or somewhere else (just not mine please ;) ) Here I used the one you wanted to use.
But as I said, if the visitor does not have javascript enabled, the redirection will not happen.
nowhere500
10-18-2006, 06:40 AM
This code worked for me but the only problem is that I'm using blogger, generating a new page every time I post to my blog. I've blocked my stalker from my index page. I'm wondering if there's a way to block my stalker from accessing every page of my website.
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.