Conditional Redirect using PHP

by Rekha 2010-02-09 12:27:37

Conditional Redirect

You can also use PHP code to send the redirect based on some desired condition. For example, the following code will only send the redirect if the user agent was referred from a specified domain:

<?php
$referer = $_SERVER['HTTP_REFERER'];
$domain_name = "xxx.com";
if(strpos($referer, $domain_name)!== FALSE) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/newpage.php");
exit;
}
?>

Tagged in:

1362
like
0
dislike
0
mail
flag

You must LOGIN to add comments