douhao2153 2019-06-13 09:37
浏览 775

标头未使用Referrer-Policy进行设置

I have a domain lets say www.domain.com which i am redirecting to www.whatismyreferer.com to check referer. When i redirect page using PHP headers it shows No referer / hidden in result. I want to set referer as www.domain.com on whatismyrefer.com

Here is my code on the index.php file of www.domain.com:

<?php

header("Referrer-Policy: origin");
header("Location: https://www.whatismyreferer.com",true, 302);
?>

I have also tried referrer-policy: unsafe-url but still gets no referer

But if i use:

<meta name="referrer" content="origin">
<meta http-equiv="refresh" content="0;https://www.whatismyreferer.com">

then it shows referrer. I dont want to do it with meta tags, i want to do it with header location

  • 写回答

1条回答 默认 最新

  • dpgu5074 2019-06-13 14:59
    关注

    I think the problem is probably how you are testing it. The 3xx redirect preserves the original Referer - the browser won't set a new Referer on the redirect itself. So, if you are directly requesting .index.php on your site (no referer) then there will also be no referer on the redirected request.

    The meta refresh is not a 3xx HTTP redirect and behaves like you are following a regular anchor/link, so the browser generates a Referer.

    Instead, you would need to test with a secondary file (eg. test-referer.html) that links to index.php in order to generate a Referer before testing your redirect/Referrer-Policy header.

    <!-- test-referer.html -->
    <a href="/index.php">index.php</a>
    

    UPDATE:

    The Referrer-Policy header works correctly for me when tested in this way.

    I want to set referer as www.domain.com on whatismyrefer.com

    In that case, you can't simply use 3xx HTTP redirects (without an initial referrer) because 3xx redirects don't themselves generate a referrer (as mentioned above). If 3xx redirects generated a Referer then sites would have problems with lost referrers all the time due to canonical redirects etc.

    You will need to use a meta refresh (as you suggested) or perhaps a JavaScript "redirect" (untested). Or you could perhaps use CURL if the intention is to simply "fake" the Referer - although this won't directly result in a redirect.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘