Page 1 of 1

trying to redirect based on ip address without success??

Posted: Tue Sep 01, 2009 9:20 pm
by techexpressinc
Objective is to redirect the website user based on the location. If the user is at the office at a specified ip address, when an icon is clicked they will have access to the employee area. If the user is not at the specified ip address they will get a not access web page.
A icon on the home page will be an hyperlink to the following PHP code:
( ipfliper.php)

Code: Select all

<?php
if ($_SERVER['REMOTE_ADDR']=='69.245.218.248') { header('Location: http://www.turnstone.org/employee2/index.html');}
 else
 { header('Location: http://www.turnstone.org/notatoffice.html');}
exit;
?><?php
if ($_SERVER['REMOTE_ADDR']=='69.245.218.248') { header('Location: http://www.turnstone.org/employee2/index.html');}
 else
 { header('Location: http://www.turnstone.org/notatoffice.html');}
exit;
?>
I keep trying without success? Any ideas?
Thank you Russ at Techexpressinc.com

Re: trying to redirect based on ip address without success??

Posted: Tue Sep 01, 2009 9:57 pm
by Eric!
Besides having a second set of code that is redundant, they should at least work. Have you tried echoing the IP that the server thinks it is seeing?

Re: trying to redirect based on ip address without success??

Posted: Tue Sep 01, 2009 10:45 pm
by techexpressinc
i am using this to see the ip

Using this on index2.html to get ip.
<p><script language="JavaScript">
VIH_BackColor = "palegreen";
VIH_ForeColor = "navy";
VIH_FontPix = "16";
VIH_DisplayFormat = "You are visiting from:<br>IP Address: %%IP%%<br>Host: %%HOST%%";
VIH_DisplayOnPage = "yes";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/visitor ... "></script>

Re: trying to redirect based on ip address without success??

Posted: Fri Sep 04, 2009 5:35 am
by techexpressinc
my code to identify the ip is at

http://www.turnstone.org/index2.html

any ideas of where i am going wrong? :oops:

Re: trying to redirect based on ip address without success??

Posted: Fri Sep 04, 2009 6:55 am
by AlanG

Code: Select all

<?php
if($_SERVER['REMOTE_ADDR'] == '69.245.218.248') {
    header('Location: http://www.turnstone.org/employee2/index.html');
    exit();
}
else {
    header('Location: http://www.turnstone.org/notatoffice.html');
    exit();
}
?>
I assume you have a static IP address at the office? Otherwise this code won't always work as the IP address won't always be 69.245.218.248.
The IP addresss you have on the home page is fetched using JavaScript and shouldn't interfere with this code at all.

You mentioned there is a link to this code. In that case, the user won't be redirected to the proper url until they click that link. If you want to implement this code, you should copy and paste it to whichever page requires it, or use a php include <?php include('ipfliper.php'); ?>

Re: trying to redirect based on ip address without success??

Posted: Fri Sep 04, 2009 1:13 pm
by techexpressinc
I installed the new ipfliper code you suggested.
Checked my ip at http://www.turnstone.org/index2.html - bottom of the page
It still displayed
You are visiting from:
IP Address: 69.245.218.248
Host: c-69-245-218-248.hsd1.in.comcast.net

when i executed ipfliper the screen displayed was
Not a office:
http://www.turnstone.org/notatoffice.html

I wanted the
employee/index.html

Thanks for the help, but any more good ideas??
Russ

l

Re: trying to redirect based on ip address without success??

Posted: Fri Sep 04, 2009 1:31 pm
by AlanG
Do an <?php echo $_SERVER['REMOTE_ADDR']; ?> and tell us what's displayed.

Re: trying to redirect based on ip address - not working

Posted: Fri Oct 16, 2009 6:26 am
by techexpressinc
I did get an ip. I put that ip in my php code and it directed you to the good ip url no matter what computer/location you were at. So that must be like the host server.
Any more ideas on this pbl.
Thx
Russ

Re: trying to redirect based on ip address without success??

Posted: Fri Oct 16, 2009 8:52 am
by Eric!
If your location and computer is changing but your IP isn't then you must be using a shared host provider for the other locations. It is hard to understand your explanations of your results too. What is the good ip url? Is the bad one notatoffice?

If you echo back the IP address on both the pages (good url and bad url) you will be able to see if your IP is changing. If you're accessing this server from computers in the same building, odds are good you're using a shared IP. If your "office computer" is using dynamic IP's then your IP will keep changing and your IP filter won't work.