本文介绍了如何重定向保留原始引荐来源网址字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下PHP重定向脚本:

I have the following PHP redirect script:

if ($country=="IL") { header('Location: http://iquality.itayb.net/index-he.html'); }
else { header('Location: http://iquality.itayb.net/index-en.html'); }

这将根据$country的值将用户重定向到其他页面.引荐来源网址将成为重定向页面本身.

This redirects the user to different pages, according to $country's value. The referrer becomes the redirection page itself.

如何保留原始引荐来源网址字段?

How can I preserve the original referrer field?

推荐答案

您不能使用header('Referer: SOME_REFERER_URL'),因为浏览器仍然会覆盖它.

You can not use header('Referer: SOME_REFERER_URL') because browser will overwrite it anyway.

如果您拥有重定向目标iquality.itayb.net,则有几种方法可以做到这一点:

If you own redirected targets iquality.itayb.net then there are several ways to do this:

  1. 在用户会话中保存引荐来源网址.

  1. Save referer in the user session.

// 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'];
}

  • 发送引荐作为参数:

  • Send referer as parameter:

    // 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'];
    }
    

  • 如果您想欺骗任何其他服务器,请使用以下命令:

    If you want to cheat any other server then use something like this:

    $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);
    }
    

    这篇关于如何重定向保留原始引荐来源网址字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-28 07:19