Forum Moderators: open

Message Too Old, No Replies

Using Javascript to ban IP addresses

         

mamab

1:33 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



Hello.

Any help that can be given with this problem would be appreciated.

This is the code that I have,that I tested last night upon a board set up for that.The reason being,I have trolls roaming my other boards ripping links off them,that are getting my members annoyed by doing so.I cannot seal my boards and have members only,otherwise I would do that.I just want to ban the certain addresses we have.

<script language="JavaScript">
// IP Redirect
var ip = '<!--#echo var="REMOTE_ADDR"-->' // ** Do Not Modify This Line **
if (ip == '00.00.00.00') {
alert("ACCESS DENIED!");
if (confirm("You are not authorized to view this web site!"))
{location.href="http://www.example.com/security.html" }
else
{ ("ACCESS DENIED!");
{location.href="http://www.example.com/security.html" }} }
</script>

The code works fine.Just to well-it bans anyone from viewing the test board.

[edited by: tedster at 2:36 pm (utc) on Oct. 1, 2004]
[edit reason] use example.com [/edit]

BlobFisk

3:43 pm on Oct 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, mamab!

I'm not sure if doing this on the front end is the best approach, would it not be better to do this entirely at the backend? Maybe a htaccess file ban list or something like that?

mamab

4:59 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



Thank you, both for the reply and for the edit that you have done.

I have one problem.MY boards are free boards,hence I have no files that I can edit from.I have to go through the control panel.I used this code in the header,and it did work-just that it banned us all from access.

I appreciate it is Java code and my boards are HTML format code.Just please be patient with me.I am new to this.For all I know that might be the reason why it will not work properly at all.

tedster

3:41 am on Oct 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry I didn't look a little closer from the beginning. Your script basically says "if" the ip address is xx.xx.xx.xx, then ban the person -- and "else" [in any other case] also ban the person. You don't want the "else" part. Also, your should replace the language attribute with a type attribute.

So now you have:

<script type="text/javascript">
// IP Redirect
var ip = '<!--#echo var="REMOTE_ADDR"-->' // ** Do Not Modify This Line **
if (ip == '00.00.00.00') {window.location.replace("http://www.example.com/security.html")
}
</script>

That should be all you need. Just place a suitable security note at security.html and you don't need the alert box/confirmation thing at all. It just replaces the requested page with a different page for anyone from that IP address.

[edited by: tedster at 3:49 am (utc) on Oct. 2, 2004]

adni18

3:46 am on Oct 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Either way, javascript cannot fully stop a person from seeing a page. They can always open it in notepad or something. :-(

mamab

11:39 pm on Oct 2, 2004 (gmt 0)

10+ Year Member



Thank you for the help.I mean that as in mean it.Any suggestions as to were to send them in the security note part?

Could I re-direct them back to the front of the board.By thatI mean add my own board website address ie:WWW.mamb.com?that will then have them going round again?

And I don't think these trolls will go as far as using notepad-though I thank you for telling me that.These trolls just want those links and to clog up the server.