PDA

View Full Version : IP Redirect



Sachmet
04-05-2009, 05:40 AM
Before anyone tells me you can't completely ban people with JavaScript. I do know this won't work if they disable JavScript. I am not wanting to ban just redirect some IPs. A JavaScript redirect is enough for what I need.

I have looked through tons of forums and sites. I get the same 3 or 4 types of JavaScript IP Ban/redirect. I can't do anything on the server side. I can't use PHP or shtml files. I am pretty much stuck to JavaScript, HTML, and CSS files.

So I was thinking if a friend could host the code to view IP and I embedded it to my site it will show the IP, and apply a id to it. Then I could getElementById for the person's IP address.

Something like this:

<div id="YourIP">
<script src="http://friend's server/ip.js" type="text/javascript"></script>
</div>

<script type="text/javascript">
var yourip = document.getElementById('YourIP')

var bannedIp = new Array();
bannedIp[0] = "##.###.###.###"
bannedIp[1] = "##.###.###.###"

window.onload = checkVisit;

function checkVisit() {
if (yourip == bannedIp){
Redirect();
}
}

function Redirect(){
location.replace('http://www.google.com/');
}
</script>

I am still fairly new to JavaScript so was wondering if this even possible and I am missing something, or will this not work period?

tfit
04-05-2009, 06:22 PM
Can you retrieve ip's with javascript?

Sachmet
04-05-2009, 08:52 PM
Can you retrieve ip's with javascript?

Well my friend has it set up where I can paste a:
<script src="http: //friend's server/ip.js" type="text/javascript"></script> like on my site from his server and it shows the IP to the person viewing... similar to the browser detection.

Now I am not sure if the getElementById would be pulling the script link or the IP numbers.

This is nothing important I just find that if I tinker with small things and try to get things to work I learn the stuff better. And like this just wanting to know if it's possible or not. In all honesty the $40 books you get from the stores really don't help you much in the learning process.

tfit
04-06-2009, 06:55 PM
I can't help you, but why don't you ask your friend what he is doing on the server side? Because you can't do it javascript alone.

Sachmet
04-09-2009, 05:37 AM
I know JavaScript alone can't do it. There has to be something SS to do it, which my first post says I do not have access to do any SS. That is why my friend has set this up with his server. I know what my friend is doing with his server and it does not help me with what I am trying to do.

What he is doing is similar to using this:

<script src="http://embed.ipcatch.com/ip/" type="text/javascript"></script>
You can put this on your web page without having SS, and it will show the viewer their IP address.

And if I do something like:

<div id="YourIP">
<script src="http://embed.ipcatch.com/ip/" type="text/javascript"></script>
</div>

<script type="text/javascript">
var yourip = document.getElementById('YourIP')

var bannedIp = new Array();
bannedIp[0] = "##.###.###.###"
bannedIp[1] = "##.###.###.###"

window.onload = checkVisit;

function checkVisit() {
if (yourip == bannedIp){
Redirect();
}
}

function Redirect(){
location.replace('http://www.google.com/');
}
</script>
when the person views the page will a "document.getElementById" grab the link (ie < script src="http://embed.ipcatch.com/ip/" type="text/javascript">< /script>) or the IP numbers?

Cause if it grabs the numbers then this should work.