Home > PHP > Need Help With Php Redirect

Need Help With Php Redirect

August 11th, 2009

Any help would be much appreciated.

I am trying to redirect users based on the referring url. I’ve got it working based one the referring domain, but I want it to work when a query string is attached to the domain.

This is what I have so far.

PHP Code:
<?
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match(“/google.com/”,$referrer)) {
header(‘Location: http://WebsiteA.com’);
} else {
header(‘Location: http://WebsiteB.com’);
};
?>

This is what I want to happen, but I know this is not how to do it:

PHP Code:
<?
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match(“/google.com/url?q=”,$referrer)) {
header(‘Location: http://WebsiteA.com’);
} else {
header(‘Location: http://WebsiteB.com’);
};
?>

I want to only show WebsiteA.com if the referrer is google.com/url?q=xxxxxx (which includes anything that follows ‘url?q=’)

If the referrer is anything other than google.com/url?q=xxxxx or even just google.com i want the user to go to WebsiteB.com

So, a recap:

I want user to go to WebsiteA if referrer is something like google.com/url?q=widgets&url=23KLNSDL

I want the user to go to WebsiteB if referrer is anything else, even if the referrer is only google.com i want them to go to WebsiteB

Thank you for your help!


Need Help With Php Redirect

Comments are closed.
Bear