I want to redirect visitors based on their location with PHP. Is this possible?

  • Thread starter Thread starter locke577
  • Start date Start date
L

locke577

Guest
I'm using my website as an example of my work for a college application, and I'd like to redirect them(once they visit it) to a page I've made that shows off all of my website. Does anyone know of any code that can specify a certain IP range to forward, while ignoring the rest?


I have these two examples of code to look at:

<?
$visitor = $_SERVER['REMOTE_ADDR'];
if (preg_match("/192.168.0.1/",$visitor)) {
header('Location: http://www.yoursite.com/thank-you.html');
} else {
header('Location: http://www.yoursite.com/home-page.html');
};
?>

AND


<?if (getenv(HTTP_X_FORWARDED_FOR)) {
$ipaddress = getenv(HTTP_X_FORWARDED_FOR);
} else {
$ipaddress = getenv(REMOTE_ADDR); }
?>

Basically, I want to redirect all IPs from xx.xxx.nnn.xx
Where "nnn" is my target area.


But maybe I'm overcomplicating it.
Please help.


Thanks.
Isn't there something more simple than that?

I just need to parse the third set of numbers. how do I do that?
 
have a look here

http://www.tutorialized.com/view/tutorial/Redirect-a-User-Based-on-His-Geographic-Location/16521
 
have a look here

http://www.tutorialized.com/view/tutorial/Redirect-a-User-Based-on-His-Geographic-Location/16521
 
Back
Top