Home  >  Article  >  Backend Development  >  PHP cannot obtain Referer troubleshooting

PHP cannot obtain Referer troubleshooting

WBOY
WBOYOriginal
2016-07-30 13:31:081844browse

Test results:

PHP cannot obtain Referer troubleshooting

The same page is opened twice. The Referer can be obtained the first time but not the second time. I am very curious about the reason. The code of

test1.php is:

<?php echo <span>'测试来源:直接载入页面<br>';

echo <span>'<a href="test_cookie.php">进入页面</a><br>'</span>;

echo <span>'测试来源:新窗口打开<br>'</span>;

echo <span>'<a target="_blank" href="test_cookie.php">进入页面</a><br>'</span>;

the code of test_cookie.php is:

<?php date_default_timezone_set(<span>'Asia/Shanghai');<span>//设置默认时区</span>header(<span>'content-type:text/html; charset=utf8'</span>);<span>//设置返回头信息</span>
echo date(<span>'Y-m-d H:i:s'</span>);
echo <span>"<br>\r\n"</span>;

echo <span>'PHP获取Refer是:'</span>;
$refer=isset($_SERVER[<span>'HTTP_REFERER'</span>])?$_SERVER[<span>'HTTP_REFERER'</span>]:<span>'No refer found'</span>;
echo $refer;
echo <span>"<br>\r\n"</span>;

echo <span>'JS获取Refer是:'</span>;
    echo <span>"<script>document.writeln(document.referrer);</script>"</span>;
echo <span>"<br>\r\n"</span>;

  

I am extremely curious as to why I can get it the first time but not the second time.

The environment is LNMPA, the official one is http://lnmp.org/lnmpa.html

Use charles to capture packets under Mac

The header of test1.php requested twice is consistent.

The header of the two requests to test_cookie.php is consistent.

Then the question arises, what is the reason why PHP cannot get the referral due to two identical requests? Kneel down and ask for answers.

For more exciting topics, follow Xiaowu’s blog http://www.lingdonge.com

The above introduces the troubleshooting of the problem that PHP cannot obtain the Referer, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn