简体   繁体   English

PHP HTTP_REFERER和锚标记href

[英]PHP HTTP_REFERER and anchor tag href

I'm trying to get the referer url on destination website by using $_SERVER['HTTP_REFERER'] . 我正在尝试使用$_SERVER['HTTP_REFERER']在目标网站上获取referer url。

example.com example.com

<a href="example2.com">Click Me</a>
<a href="example2.com/page/2">Click Me</a>
<a href="example2.com/page/3">Click Me</a>
<a href="example2.com/page/4">Click Me</a>

example2.com example2.com

echo $_SERVER['HTTP_REFERER'];

The result is blank. 结果是空白的。 I clicked on the link. 我点击了链接。 How do i solve this? 我该如何解决这个问题? Can $_SERVER['HTTP_REFERER'] work with external domains? $_SERVER['HTTP_REFERER']可以与外部域一起使用吗?

The address of the page (if any) which referred the user agent to the current page. 将用户代理引用到当前页面的页面地址(如果有)。 This is set by the user agent. 这是由用户代理设置的。 Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. 并非所有用户代理都会设置此功能,有些用户可以将HTTP_REFERER修改为功能。 In short, it cannot really be trusted. 简而言之,它无法真正被信任。

Refer to the PHP Manual 请参阅PHP手册

To prevent this error try 要防止此错误,请尝试

if(isset($_SERVER['HTTP_REFERER'])) {
  echo $_SERVER['HTTP_REFERER'];
}

OR 要么

echo isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';

It cant be relied upon. 它无法依靠。

The address of the page (if any) which referred the user agent to the current page. 将用户代理引用到当前页面的页面地址(如果有)。 This is set by the user agent. 这是由用户代理设置的。 Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. 并非所有用户代理都会设置此功能,有些用户可以将HTTP_REFERER修改为功能。 In short, it cannot really be trusted. 简而言之,它无法真正被信任。

PHP Manuel PHP Manuel

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

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