Is it possible to remove the referrer in PHP before redirected?

守給你的承諾、 提交于 2019-12-09 18:48:01

问题


But since the browser is the only thing that manages the referrer, however I was thinking about a script that removes the referrer before they are redirected to the link they want to go to.

For example,

http://mywebsite.com/url.php?u=http://www.stackoverflow.com

Where url.php could remove the referrer and then redirect. Is it possible to do this in any way?


回答1:


If your redirect is an HTTP redirect then, no, you have no control over that.

Nor, frankly, should you. It's the browser's business to form the REFERER value, not yours.




回答2:


You can actually do this in practice if you're running HTTPS on your webserver. You need to force the connection to go via HTTPS as an intermediary so the sequence of redirects would then be:

  1. http://mywebsite.com/url.php?u=http://www.stackoverflow.com ->
  2. https://mywebsite.com/url.php?u=http://www.stackoverflow.com ->
  3. http://stackoverflow.com

Most browsers don't send a referrer in cases like that to avoid leaking information that was private and encrypted over insecure channels to unrelated third parties.


Newer browsers now support this properly anyway, with a meta tag. You can add:

<meta name="referrer" content="never">

Generally though you should be setting this option on all your pages anyway, so both client and server side redirection would be fine.




回答3:


The referer comes from the browser, which you already indicated you understand.

This would be simple enough for you to write a quick test.

Theoretically if you are redirecting to a script that then redirects again, the referer is going to be the redirector script and not the original script.

If you're asking if your script can redirect "invisibly" -- then no, that is outside of the script's control.




回答4:


try this code:

$url = 'your target';
header("HTTP/1.1 301 Moved Permanently");
header( "Location: $url" );


来源:https://stackoverflow.com/questions/7183212/is-it-possible-to-remove-the-referrer-in-php-before-redirected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!