简体   繁体   English

重定向时更改引用者

[英]Change referrer when redirecting

What I'm trying to do is use PHP to redirect from web site A to web site B (both are different domains), but I want the referrer in the HTTP headers to be set to web site A (the page that performed the redirect). 我想要做的是使用PHP从网站A重定向到网站B(两者都是不同的域),但我希望HTTP标头中的引荐来源设置为网站A(执行重定向的页面) )。 So, that is, web site B will see web site A as a referrer. 因此,也就是说,网站B将网站A视为推荐人。

您可以在您的网站A上使用类似<meta http-equiv="refresh" content="1;url=http://siteb.net">内容。

I'm pretty certain that the sending the referrer is ultimately up to the web browser, not PHP. 我很确定发送引用者最终是由Web浏览器决定的,而不是PHP。 You could probably send the address via $_GET though. 您可以通过$_GET发送地址。

Edit: You won't be able to change the referrer (misread the post, derp). 编辑:您将无法更改引荐来源(误读帖子,derp)。

I've checked using localhost and a dummy script. 我已经使用localhost和一个虚拟脚本进行了检查。 The browser does send the referer in the HTTP even at redirections. 即使在重定向时,浏览器也会在HTTP中发送引用。

To test this, I created a script called testRefererRedirect.php : 为了测试这个,我创建了一个名为testRefererRedirect.php的脚本:

<?php

if($_GET['a']){

    if($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != 'off'){

        echo $_SERVER['HTTP_REFERER'];

    }else{

        header('Location: https://localhost/testrefererredirect.php?a=1');

    }

}else{

    echo '<a href="testrefererredirect.php?a=1">test</a>';

}

To emulate cross domains, I used HTTP and HTTPS for my local server. 为了模拟跨域,我使用HTTP和HTTPS作为本地服务器。

On first load, the page will show a link: I will click this link to allow the browser to send the referer in the headers. 首次加载时,页面将显示一个链接:我将单击此链接以允许浏览器在标题中发送引用。 Next, because I load the page initially in HTTP the header function will be called. 接下来,因为我最初在HTTP中加载页面,所以将调用头函数。 Finally, the HTTP referer header meant for the 2nd step showed up in the 3rd step. 最后,第二步中出现的HTTP referer标题出现在第3步中。

Conclusion 结论

You can safely use $_SERVER['HTTP_REFERER'] on website B to capture the refer information meant for website A if you do redirection on website A. 如果您在网站A上进行重定向,您可以安全地在网站B上使用$_SERVER['HTTP_REFERER']来捕获针对网站A的引用信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM