View Full Version : detect and redirect client IP address
kbardolf
08-29-2002, 04:32 PM
I need to detect the client IP address and then redirect them to the apporiate page depending on their IP. This is on an Intranet site. Here's what I've been working with:
var ip = '<!--#echo var="REMOTE_ADDR"-->';
if (ip == "10.256.85");
{
url=("http://www.google.com");
window.location=url;("http://www.google.com");
}
This works for the redirect but doesn't check the IP.
Thank you!
K. Bardolf:confused:
beetle
08-29-2002, 05:13 PM
if (ip == "10.256.85"); <-- Remove that semicolon!
{
var nUrl="http://www.google.com";
window.location.href=nUrl;
}
kbardolf
08-29-2002, 05:23 PM
Thank you for the prompt reply. I removed the semicolon but it still didn't work. Any other suggestions? Please...:confused:
beetle
08-29-2002, 05:31 PM
I don't follow. What's the problem? Is the 'ip' variable empty? If so, what server-side setup up populating it?
Are you getting a javascript error? Or does it just not work?
joh6nn
08-29-2002, 06:11 PM
that's not going to work, dude. as far as your script is concerned, the IP address is always going to be "<!--#echo var="REMOTE_ADDR"-->". the SSI include isn't going to happen.
this isn't the sort of thing that can be done with javascript. you need a server side language. or maybe .htaccess files.
kbardolf
08-29-2002, 06:57 PM
Once I removed the semicolon and tested it, I got an error message that said, "Done, but with errors."
Yes, the variable is empty because it's supposed to retreive the clients IP. Once it does that, I need the script to check to see where that particular IP gets redirected. That's why I have the if statement. However, I'm obviously not on the right track.
if (ip == "10.256.85");
{
url=("http://www.google.com");
window.location=url;("http://www.google.com");
So you think server side is the answer?
thanks so much!
Kristen
worldtravlur
09-13-2010, 09:17 PM
I'm looking to do the same thing. I need to be able to redirect employees who access our intranet from home to one site while employees who access our intranet from work see a different site.
I'm completely lost on where to start. Any suggestions?
Philip M
09-13-2010, 09:47 PM
This is an ancient thread, long concluded.
You can only detect the user's IP address with server-side scripting.
<?
//"ip.php" example- display user IP address on any page
Header("content-type: application/x-javascript");
$serverIP=$_SERVER['REMOTE_ADDR'];
echo "document.write(\"<center><font face='COMIC SANS MS,ARIAL' size='2' color = '#DC143C'><b>Your IP address is: " . $serverIP . "</b>\")";
?>
But I do not really see how you can tell whether the user is idling his time away at home or in his office!
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
worldtravlur
09-14-2010, 01:57 PM
Thank you Philip M, that helps out a lot. I do apologize for responding to an ancient thread; I probably should have started a new one.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.