...

View Full Version : Website redirecting -- how?



dantm
06-02-2004, 01:56 PM
Hi, I am trying to keep a specific subdomain from seeing my webpage, something like

192.168.X.X

Would it be possible to have a start-up JavaScript which checks the IP and then if it falls in those ranges to redirect them to Yahoo for example, and if it doesn't then to load the website normally?

Does anybody have code examples?


THANKS!!!

jbot
06-02-2004, 02:06 PM
you can't detect IP addresses thru JS as such, but you can - if it's an Apache server, that is - get the IP using the server's environment variables. you can then append that info to a JS variable and call a function which redirects based on that info.

dantm
06-02-2004, 08:48 PM
Thanks!!!

How would this be done using JavaScript considering that the web server is Apache? Can anybody point me in the right direction on where I should look for a function?

THANKS!!!

jbot
06-03-2004, 09:28 AM
this is what you want:


<script type="text/javascript">

var sIp = '<!--#echo var="REMOTE_ADDR" -->' ;

window.onload
{
switch (sIp)
{
case "SOME_IP_NUMBER": location.replace(SOME_URL_STRING); break;
}
}


</script>

glenngv
06-03-2004, 09:49 AM
this is what you want:


<script type="text/javascript">

var sIp = '<!--#echo var="REMOTE_ADDR" -->' ;

window.onload
{
switch (sIp)
{
case "SOME_IP_NUMBER": location.replace(SOME_URL_STRING); break;
}
}


</script>


window.onload=function()
{
switch (sIp)
{
case "SOME_IP_NUMBER": location.replace(SOME_URL_STRING); break;
}
}

jbot
06-03-2004, 10:36 AM
hi Glenn,

Believe it or not, the script doesn't need your addition to work. performs just fine without it. :p

glenngv
06-03-2004, 10:48 AM
Even if it does work, it's better to do it the normal way to avoid confusion especially for the js newbies.

jbot
06-03-2004, 11:01 AM
it's better to do it the normal way to avoid confusion especially for the js newbies.

och, that spoils all the fun LOL

you'd also be right in a readability sense, but I've gotten into the habit of writing more shortand than usual. tricks me into thinking i'm more advanced than before
;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum