PHP stores information about the referring URL in one of its global variables - $_SERVER. You can easily access that value using the $_SERVER['HTTP_REFERER']. Now what you have to do is to see if any of the 2 domains is in that HTTP_REFERER variable. You can do this using he preg_match function.

This is the code that you can use:

PHP Code: 
<?
$referrer 
$_SERVER['HTTP_REFERER'];
if (
preg_match("/site1.com/",$referrer)) {
      
header('Location: http://www.customercare.com/page-site1.html');
} elseif (
preg_match("/site2.com/",$referrer)) {
      
header('Location: http://www.customercare.com/page-site2.html');
} else {
      
header('Location: http://www.customercare.com/home-page.html');
};
?>
Note, that because of using the header() function that code has to be put on the very top of your PHP page. Header redirect will throw an error if there is something sent to visitors browser before calling it.

Instead of using $_SERVER['HTTP_REFERER'] you can use $_SERVER['REMOTE_ADDR'] which carries information about visitors IP address. This way you can redirect users based on their IP address. If you detected that someone is trying to hack your web site you can use that PHP redirect to send him to a ?Thank you page?

PHP Code: 
<?
$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');
};
?>


I think that shud help you
0ccul7 Reviewed by 0ccul7 on . User redirection based on Location?? Hi, Can any one tell me the html code for User redirection based on Location i.e if any user visit our website usa it should direct them to .us domain instead of .com domain. thx Rating: 5