PDA

View Full Version : Blocking IP numbers with Javascript???


Rockrz
11-21-2002, 04:45 AM
How do I block an IP number of someone who is a real a** from viewing my business website?

He's using Roadrunner, so I'm hoping his IP number should be fairly constant.

Any ideas on how to accomplish this would be greatly appreciated!

kwhubby
11-21-2002, 07:00 AM
unfortunatly, javascript does not have a way of getting your ip address, its something that you would need a server side language, java applet might work

mhere
11-21-2002, 08:39 AM
someone posted this link about .htaccess in this forum. it can help u to block ip addresses:

http://www.javascriptkit.com/howto/htaccess.shtml

Rockrz
11-21-2002, 04:09 PM
I can't password protect my site. Then nobody would be able to see it.

There IS a javascript that will basically re-direct specific IP number to another page, which is all I want to do.

I saw this script once and didn't save it because I didn't think I would ever need it. I saw it on some site where you can download javascipts.

I'll continue my search . . .

beetle
11-21-2002, 04:12 PM
You sure it wasn't server-side javascript that you saw? (Yes, it exists, but nobody uses it)

MCookie
11-21-2002, 04:41 PM
> > I can't password protect my site. Then nobody would be able to see it.
That is not what Mhere meant by pointing you to the htaccess tutorial.

If you can use .htaccesses you can easily block just one IP:
http://www.javascriptkit.com/howto/htaccess5.shtml

Rockrz
11-21-2002, 06:50 PM
I'm pretty sure it was just a few lines of code placed in the head of a webpage. It's been months ago since I've seen it.

I'll go back & re-read that page on .htaccess and see if it says anything about blocking IP numbers.

I thought all it was talking about was password protecting folders, so you can require a username & a password.

joh6nn
11-21-2002, 06:54 PM
.htaccess lets you do lots of different things. the first link, lead to the entire tutorial, the first page of which, talks about passwords, if i remember correctly. a page or two later, it talks about banning IPs.

there are a couple of javascripts, that claim to block IP. they either don't work, or don't work as well as .htaccess. you're better of using .htaccess, if you can, or some other server-side script.

i know for a fact that there's at least one thread in this forum, that i posted in, with code that will work with IPs, IF you have SSI. but i need to point out, that it won't do nearly as good a job as .htaccess.

Rockrz
11-22-2002, 12:36 AM
OK. Thanks.

Sounds like I need to dig in and take a crash course on .htaccess

piniyini
11-22-2002, 05:51 PM
Hey, is this what you're looking for ?

http://www.javascriptkit.com/script/script2/blockip.shtml

I'm sure you know how to modify it to suit your needs.

I havnt tried it out, so I'm not sure if it works proberly or not.

Laterz ...

joh6nn
11-22-2002, 08:43 PM
that particular script, doesn't work at all.

Rockrz
11-23-2002, 12:44 AM
You know, I think that WAS the one I saw a few months back.
I'll do some testing to see how it works and let you know if it works, or not.

I hope I don't lock myself out of my own website...LoL....
I'll use different test pages and just delete them if it does work.

Thanks for the lead!

Rockrz
11-23-2002, 01:21 AM
Hey joh6nn....

You're absolutely right. It no workie...
Now I know why the credit isn't available!

whammy
11-23-2002, 01:28 AM
Actually it should work if you are on an SSI enabled server, AND you have named the page extension you're using it on to .shtml.

I remember testing this and it worked just fine.

beetle
11-23-2002, 02:06 AM
Originally posted by whammy
Actually it should work if you are on an SSI enabled server, AND you have named the page extension you're using it on to .shtml.

I remember testing this and it worked just fine. Same here. Rockrz, this is the exact same method I showed you at Sitepoint... (http://www.sitepointforums.com/showthread.php?s=&threadid=83909)

joh6nn
11-23-2002, 02:25 AM
actually, it shouldn't work. SSI directives aren't executed inside script tags.

if you want to access SSI variables from javascript, you have to make them the values of form fields (http://www.codingforums.com/showthread.php?s=&threadid=5725). and that's still not as reliable as .htaccess.

beetle
11-23-2002, 02:48 AM
Well, I'll be honest, I don't know how it's supposed to work, I just know that the method I posted does. I tested it.

Rockrz
11-23-2002, 03:15 AM
OK. I am on SSI enabled servers, but all my pages are .html

beetle
11-23-2002, 03:41 AM
How many pages? I mean, if you don't change the files (just a simple extension change) then you'll have to use something else. You've got the info. The choice is yours.

joh6nn
11-23-2002, 04:10 AM
beetle, when you tested, how did you confirm the contents of the variable? because as far as i know, SSI shouldn't run inside script tags, and a few months ago, when this first came to my attention, i tested to make sure i was right, and the example that you've posted, did not work for me.

whammy
11-23-2002, 04:24 AM
Hmm, I tested it before and it worked, too... lemme test it again and give you what I come up with. ;)

whammy
11-23-2002, 04:29 AM
http://www.solidscripts.com/testipblocker.shtml

As you can see, it seems to work just fine as long as you don't use the

<!--
//-->

around it inside your script tags.

This is because the SSI is processed before it is sent to the browser. I'm guessing that it isn't read properly by the server if you have a starting comment tag before that in the script... i.e. <!--

:D

joh6nn
11-23-2002, 04:45 AM
whammy, that's a good observation, but i know i didn't use the comments in my test script. i tested your page on my site, and i get the same, positive results, but i've switched hosts, since the last time i tried this, and i can't verify the results that i got the last time. i'm fairly certain of those results though (90%), and my conclusion is that it varies, dependent on server configuration.