我有以下 PHP 重定向脚本:
if ($country=="IL") { header('Location: http://iquality.itayb.net/index-he.html'); }
else { header('Location: http://iquality.itayb.net/index-en.html'); }
根据$country
's 的值,这会将用户重定向到不同的页面。推荐人成为重定向页面本身。
如何保留原始推荐人字段?
我有以下 PHP 重定向脚本:
if ($country=="IL") { header('Location: http://iquality.itayb.net/index-he.html'); }
else { header('Location: http://iquality.itayb.net/index-en.html'); }
根据$country
's 的值,这会将用户重定向到不同的页面。推荐人成为重定向页面本身。
如何保留原始推荐人字段?
您不能使用header('Referer: SOME_REFERER_URL')
,因为浏览器无论如何都会覆盖它。
如果您拥有重定向目标iquality.itayb.net
,那么有几种方法可以做到这一点:
在用户会话中保存referer。
// in your first script save real referer to session
$_SESSION['REAL_REFERER'] = $_SERVER['HTTP_REFERER'];
// in the redirected script extract referer from session
$referer = '';
if (isset($_SESSION['REAL_REFERER'])) {
$referer = $_SESSION['REAL_REFERER'];
unset($_SESSION['REAL_REFERER']);
}
else {
$referer = $_SERVER['HTTP_REFERER'];
}
发送referer作为参数:
// in your first script
header('Location: http://iquality.itayb.net/index-he.html?referer=' . $_SERVER['HTTP_REFERER']);
// in your refered script extract from the parameter
$referer = '';
if (isset($_REQUEST['referer'])) {
$referer = $_REQUEST['referer'];
}
else {
$referer = $_SERVER['HTTP_REFERER'];
}
如果您想欺骗任何其他服务器,请使用以下内容:
$host = 'www.yourtargeturl.com';
$service_uri = '/detect_referal.php';
$vars ='additional_option1=yes&additional_option2=un';
$header = "Host: $host\r\n";
$header .= "User-Agent: PHP Script\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Referer: {$_SERVER['HTTP_REFERER']} \r\n";
$header .= "Content-Length: ".strlen($vars)."\r\n";
$header .= "Connection: close\r\n\r\n";
$fp = fsockopen("".$host,80, $errno, $errstr);
if (!$fp) {
echo "$errstr ($errno)<br/>\n";
echo $fp;
} else {
fputs($fp, "POST $service_uri HTTP/1.1\r\n");
fputs($fp, $header.$vars);
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}