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?
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?