BCLS Tech
asked on
looking for php redirect based on ip address
I am looking for a php script that will determine a users ip address and send them to a particular url.
For example.
If users IP starts with 10 then send to this URL1
If users IP starts with 192.168.1 then send to URL1
Else
send the user to URL2
Any help would be greatly appreciated.
For example.
If users IP starts with 10 then send to this URL1
If users IP starts with 192.168.1 then send to URL1
Else
send the user to URL2
Any help would be greatly appreciated.
ASKER
Works! Sort of...
Can another condition be added for URL 1?
If users IP starts with 10 then send to this URL1
If users IP starts with 192.168.1 then send to URL1
IF users IP starts with 172.168.1 then send to URL 1
Else
send the user to URL2
Can another condition be added for URL 1?
If users IP starts with 10 then send to this URL1
If users IP starts with 192.168.1 then send to URL1
IF users IP starts with 172.168.1 then send to URL 1
Else
send the user to URL2
I think you meant '172.16.1'... 172.168.1.x is not a private IP block so wouldn't be found on an internal LAN.
<?php
$rmtip = $_SERVER['REMOTE_ADDR'];
if ((substr($rmtip,0,2) == "10") || (substr($rmtip,0,9) == "192.168.1") || (substr($rmtip,0,8) == "172.16.1")) header('Location: http://www.URL1.com/');
else header('Location: http://www.URL2.com/');
exit;
?>
ASKER
We have both public and private IP's.
Is there a way to get our private and public IP blocks to point to URL1 but all other public ip blocks to default to the Else?
Hope I said that right.
Is there a way to get our private and public IP blocks to point to URL1 but all other public ip blocks to default to the Else?
Hope I said that right.
Well, just do more of the same. Is that code doing what you want so far? There are also methods of redirecting on the server itself. If you're interested in that, you should 'Request Attention' and get your server's zone added to this question.
ASKER
10 is working and taking me to the internal site
Our systems with public IP's do not seem to be working.
If I can find it, would it help If I sent you the ASP script that was on our old server?
It was doing the job until the new server and new site was put online. Problem is we don't have asp on the new server.
Our systems with public IP's do not seem to be working.
If I can find it, would it help If I sent you the ASP script that was on our old server?
It was doing the job until the new server and new site was put online. Problem is we don't have asp on the new server.
Sure, the ASP script would have the details you're talking about.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked flawlessly.
ASKER
Thank you!
Open in new window