Redirect based on referer's url

Posted by steve on Stack Overflow See other posts from Stack Overflow or by steve
Published on 2010-06-12T13:49:42Z Indexed on 2010/06/12 14:13 UTC
Read the original article Hit count: 221

Filed under:
|
|

I am trying to redirect visitors to a site based on their referring url.

Here is the script:

php
$domain='blankds.com';
$referrer=$_SERVER['HTTP_REFERER'];
echo $referrer;
if (preg_match("/$domain/",$referrer)) {
 header('Location: http://www.blackisgreen.org/page_1.php');
 } else {
 header('Location: http://www.blackisgreen.org/page_2.php');
};

Errors: I get a "Warning: cannot modify header" error because I am echoing $referrer before sending headers.

If I remove the echo the script does not work.

Any suggestions?

© Stack Overflow or respective owner

Related posts about php

Related posts about redirect