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)

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

If they are at the office presumably turnstone, are they on a company intranet, the ip reported may not be the external ip expected, it may be the intranet 192.168.*.*, or similar

no external file ip redirect

<a href="<?php ( $_SERVER['REMOTE_ADDR']== '69.245.218.248' ) ? ( echo 'http://www.turnstone.org/employee2/index.html'; ) : ( echo 'http://www.turnstone.org/notatoffice.html'; ) ?>">link title</a>

also allowing for users who write down the filename at work and type it in at home add a redirect to the /employee2 file to bounce them to 'notatoffice' if that too is not at the required IP

edit:?dunno Why: click plain text toggle and the code looks right, in php there is an extra echo ?

http://validator.w3.org/check?uri=http%3A%2F%2Ftechexpressinc.com%2F&charset=%28detect+automatically%29&doctype=Inline&group=0

http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Ftechexpressinc.com%2F&profile=css21&usermedium=all&warning=1&lang=en

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/visitorIPHOST.js.php"></script>

I do not suggest the code was the fault
the code in the op works,
its just longer and uses external files

the Fix, is the ip, $_SERVER["REMOTE_ADDR"] is not returning the expected result
add echo $_SERVER["REMOTE_ADDR"]; to check what the result is
the code produced verifies the external ip. - what you see from your office if you ping the client's dotcom
the external ip may not be the one presented to the script when the script is running on the client's intranet. intranet ips typically are in the range 192.168.0.*
the external ip is not static and varies whenever the ISP alters it

the javascript in php that is giving the ip is externally hosted.
only the external ip will be returned by that script,
that script is php outputting javascript so the logic used to generate the javascript is not viewable
I still think that turnstone is likely to have more than one pc on an intranet, and your script is receiving the local intranet address not the external IP coded for
I can (dis)prove this assumption from within turnstone, <?php echo $_SERVER['REMOTE_ADDR']; ?> but I don't know how to do it remotely

The first thing you must figure out is what IP the intranet is going to read, whether it be internal or external IP.

Once you have found this out then it will be easier to use the IP to refer. If it reads internal then it is most likely you need PHP to do a lookup on an IP range.

Although if I understand right there is a security flaw with this method as if someone finds out the address of the employee area then they could just enter that URL into the browser and get there anyhow...

Is it not a better idea to make a login system then transfer them post login to the area they are required to be.

The first thing you must figure out is what IP the intranet is going to read, whether it be internal or external IP.

Once you have found this out then it will be easier to use the IP to refer. If it reads internal then it is most likely you need PHP to do a lookup on an IP range.

Well actually php can only detect the external ip address. So basically the ip provided by the isp is the ip that php receives. I would suggest running a test script such as the following:

<?php
if ($_SERVER['REMOTE_ADDR']=='69.245.218.248') {
    header('Location: http://www.turnstone.org/employee2/index.html');
    } else {
    file_put_contents('iplog.txt',$_SERVER['REMOTE_ADDR']);
    header('Location: http://www.turnstone.org/notatoffice.html');
    }
exit;
?>

Then see what ip address is placed in that text file. This will determin what ip address should be placed in the if statement. Also note that using just an ip address to separate the admin section is not secure because somebody can foward their ip through your computers ip address allowing others to gain access.

When I run an IP check on a local machine using the remote_addr method I get an internal IP, as this is an intranet I would presume it would do the same.

When I run an IP check on a local machine using the remote_addr method I get an internal IP, as this is an intranet I would presume it would do the same.

Thanks, I thought so, but was not sure it would be the same for everybody,

have found a tool at auditmypc.com that can report the external ip and internal ip but it has to run from the pc in question
at least it gives a base
My thought is any pc on the intranet will have a range in the same numbers

may be better to use a login, and report the ip addresses of each access so the boss can "please explain" if there are unusual accesses

My thought is any pc on the intranet will have a range in the same numbers

Well all the internal ip address have the same first three number but the last number varies (eg. 123.234.345.xxx). Then in the last number, I think it starts at 100 and counts up. So say your first machines ip address was 123.234.345.100 (and the first machine allways has 100 at the end) then the following ip addresses are the next 10 machines on the network

123.234.345.101
123.234.345.102
123.234.345.103
123.234.345.104
123.234.345.105
123.234.345.106
123.234.345.107
123.234.345.108
123.234.345.109
123.234.345.110

As I mentioned earlier, it is possible for a hacker to pretend their ip address is any of those internal ip addresses so they can gain access that is why I would suggest using at least a password for the admin section. Hope that explains it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.