The following are some methods you can use to redirect users from one place to another. I generally use 301 redirects for anything where I want the referer passed through because this is the fastest. Double meta refresh for anything where blank referer is important and a custom script which incorporates the form submit redirect to fake the referer where this is necessary.
Getting the right redirect is important to ensure you aren’t giving away your traffic sources.
Method 1 – Standard 301 Redirect
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.domain3.com/tmp/showreferer.php");
exit();
?>
This passes the referer through and is also the best method to pass PageRank/GoogleJuice through from one URL to another.
Method 2 – 302 Redirect
<?php
header("Location: http://www.domain3.com/tmp/showreferer.php");
exit();
?>
Temporary redirect, pretty much same as 301 except frowned upon by Google.
Method 3 – Meta refresh
<?php
$searchlink = 'http://www.domain3.com/tmp/showreferer.php
';
echo "<html>
<head><title>Loading...</title></head>
<body>
<meta http-equiv=\"refresh\" content=\"0;url=".urlencode($searchlink)."\">
</body>
</html>";
exit();
?>
About 95% of the time this will blank the referer. The other advantage of a meta refresh is you can call it at any point in a html page where as the 301 redirects have to be sent in the header.
Method 4 – Double Meta refresh
<?php
$searchlink = 'http://www.domain3.com/tmp/showreferer.php
';
$hidedomain = 'domain1.com';
if(strpos($_SERVER[‘HTTP_REFERER’],$hidedomain) !== false) {
echo ‘<html><head><title>Loading…</title></head><body>’;
echo “<meta http-equiv=\”refresh\” content=\”0;url=”.’http://’.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’].”\”>”;
echo ‘</body></html>’;
exit;
}
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: $searchlink”);
exit();
This is guaranteed never to pass the original domain through.
Method 5 – Javascript redirect
<?php
$searchlink = 'http://www.domain3.com/tmp/showreferer.php
';
echo '<html><head><title>Loading...</title></head><body>'.
"<script type=\"text/javascript\">
window.location.href='$searchlink';
</script>".
'</body></html>';
exit;
}
?>
Simple javascript redirect.
Method 6 – Form Submit
<?php
$searchlink = 'http://www.jimbop.com/tmp/showreferer.php';
echo '<html><head>
<script type="text/javascript" defer="defer">
document.forms[0].submit();
</script>
</head>
<body>
<form action="'.$searchlink.'" method="get"></form>
</body>
<html>';
?>
This can be used to fake a referer from any domain you have access to.
Below is a PHP Script you can use to check whether the referer is showing.
<?php
if(isset($_SERVER['HTTP_REFERER'])) {
echo $_SERVER['HTTP_REFERER'];
} else {
echo 'Nope';
}
?>