Home > Backend Development > PHP Tutorial > PHP无法获取Referer有关问题排查

PHP无法获取Referer有关问题排查

WBOY
Release: 2016-06-13 12:24:01
Original
1422 people have browsed it

PHP无法获取Referer问题排查

测试结果:

good

 

同一个页面,2次打开,第一次能获取到Referer第二次获取不到,很好奇原因所在。

 

test1.php代码是:

<?phpecho <span class="str">'测试来源:直接载入页面<br/>'</span>;echo <span class="str">'<a href="test_cookie.php">进入页面</a><br/>'</span>;echo <span class="str">'测试来源:新窗口打开<br/>'</span>;echo <span class="str">'<a target="_blank" href="test_cookie.php">进入页面</a><br/>'</span>;
Copy after login

test_cookie.php的代码为:

<?phpdate_default_timezone_set(<span class="str">'Asia/Shanghai'</span>);<span class="rem">//设置默认时区</span>header(<span class="str">'content-type:text/html; charset=utf8'</span>);<span class="rem">//设置返回头信息</span>echo date(<span class="str">'Y-m-d H:i:s'</span>);echo <span class="str">"<br/>\r\n"</span>;echo <span class="str">'PHP获取Refer是:'</span>;$refer=isset($_SERVER[<span class="str">'HTTP_REFERER'</span>])?$_SERVER[<span class="str">'HTTP_REFERER'</span>]:<span class="str">'No refer found'</span>;echo $refer;echo <span class="str">"<br/>\r\n"</span>;echo <span class="str">'JS获取Refer是:'</span>;    echo <span class="str">"<script>document.writeln(document.referrer);</script>"</span>;echo <span class="str">"<br/>\r\n"</span>;  
Copy after login

极度好奇是什么原因造成的第一次能获取,第二次不能获取。

 

环境是LNMPA,官方是http://lnmp.org/lnmpa.html

 

Mac下用charles抓包

2次请求test1.php的header是一致的。

2次请求test_cookie.php的header是一致的。

 

那么问题来了,什么原因造成的2次完全一模一样的请求,PHP取不到refer。跪求解。

 

更多精彩话题关注小五博客http://www.lingdonge.com

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template