Forum Moderators: open

Message Too Old, No Replies

I need to ban an IP from my site

need a javascript code to do it

         

OCDetails

5:23 am on Sep 20, 2004 (gmt 0)

10+ Year Member



Hey there everybody. I'm learning a ton on this site. One thing that I'm not finding is how to ban an IP from my site. My site is hosted by 1and1.com. Throwing javascript code in is easy, but I don't know the code to ban a particular IP. I really only need to ban one. Is there a script for that? I found this thread... [webmasterworld.com...] but it really doesn't help. The script there bans, sure enough. The problem is that it bans everybody. How do I change that to just ban one person?

I've read about .htaccess, but from what I understand about it, the server has to be a UNIX server. I don't know if 1and1 is like that or not. Can anyone help me or perhaps point me in the right direction? I'm not having much luck with the search. I appreciate it! Its for ocdetails.com if that is something that helps. I don't know if a whois on the site would tell you anything. I really do appreciate the help in advance. I'm still learning. :)

OCDetails

5:46 am on Sep 20, 2004 (gmt 0)

10+ Year Member



I also found this thread.... [webmasterworld.com...]

That script doesn't seem to work. I've tried placing it in the head of the page and banning my own IP. It still lets me in.

Bernard Marx

11:10 am on Sep 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is likely that, for SSI to be processed on your server,
you will need to save you page with the extension, .shtml

<html>
<head>
<title>Test SSI redirection based on IP address</title>
<!--#if expr="$REMOTE_ADDR = 'nnn.nnn.nnn.nnn'" -->
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=index.htm">
<!--#endif -->
<script type="text/javascript">
// IP Redirect
var ip = '<!--#echo var="REMOTE_ADDR"-->'
document.writeln(ip)
if (ip == 'nnn.nnn.nnn.nnn')
location.replace('index.htm')
</script>
</head>
<body>

If the IP matches, a meta redirect tag is written in.<br>
So this still works with JS-disabled.

There is also a JS-based redirection as a 2nd line of defence,<br>
just in case the meta fails to work.

Really, this is best done with ASP, PHP

</body>
</html>

encyclo

11:14 am on Sep 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the server has to be a UNIX server. I don't know if (the hosting company) is like that or not

Email the hosting company's technical support with this problem and they'll tell you. ;)

Depending on their setup, you may even be able to do this in the control panel. Before testing flaky Javascript solutions to this problem, you should talk to your host who will help you through the process for your particular server.

.htaccess is by far the best way in these cases.

Rambo Tribble

12:36 pm on Sep 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just a minor clarification: .htaccess is Apache, which can run a variety of operating systems. It is most commonly found on Linux, but runs on Unix or Windows, as well.

kevinpate

12:58 pm on Sep 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The host you referenced can in fact support an htaccess file.

Whether your domain is on one of their apache servers is, however, a separate question. As someone else noted, email the tech folks at your host with the question, referencing your specific domain. They'll know without having to guess.

jdMorgan

1:08 pm on Sep 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or type your URL into the WebmasterWorld server headers checker [webmasterworld.com] to find out what kind of server you're on.

Jim

OCDetails

11:44 pm on Sep 20, 2004 (gmt 0)

10+ Year Member



Thank you very much for that advice. I really like what I get with 1and1, but their tech support isn't the greatest. I will, however, give that a shot and see how many weeks it takes for them to respond. lol Thanks again!

JAB Creations

1:45 pm on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is the wrong forum for this; this should be in an apache forum.

There are a lot of things you need to be aware of if you're trying to do this with Javascript.

First off, IPs come in two flavors, dynmaic and static. There are not enough IPs to go around and so unless you pay a little extra for a static IP, you will have a dynamic IP. Dynamic IPs change depending on the ISP. Ours has changed as often as once a day to once a month. So banning an IP may or may not be effective.

You should check your apache logs to ensure that the abuser is coming from the same IP address. If you ban the user and they appear again with a new IP, remove the old IP (unless they end up coming from that IP as well, but doubtful).

Apach uses files called .htacess. No file name, just an extension. Your FTP can filter hidden files by adding -a to the command que.

If you're on an OS that can't create a file without a name then download it from your server. Edit the following...

*************
<Files 403.shtml>
order allow,deny
allow from all
</Files>
deny from 167.#*$!.x.x
*************

403.shtml should be changed to your 403 file respectively. Make sure you do not leave an ip listed too long. The same ip address may migrate from a bum in his underwear to a 700K a month laywer looking to spend big money on your site.... well high hopes at least! :D