php 获取最后访问的页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11335873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get last page visited
提问by Ricardo Neves
I need to know if a person that comes to my website went from an another specific website. Example:
我需要知道访问我网站的人是否来自另一个特定网站。例子:
- User A visits www.youtube.com/myvideo and clicks on a link to my website.
- User B visits google, search my website and click the link.
- 用户 A 访问 www.youtube.com/myvideo 并单击指向我网站的链接。
- 用户 B 访问谷歌,搜索我的网站并点击链接。
Results Message on my page:
我的页面上的结果消息:
- User A:
Welcome! You already know how it works, register now! - User B:
Welcome! Please watch our video first at www.youtube.com/myvideo
- 用户A:
Welcome! You already know how it works, register now! - 用户乙:
Welcome! Please watch our video first at www.youtube.com/myvideo
My question is:
我的问题是:
- Is it possible to know the last url the user visited before entering my page?
I already tried$_SERVER['HTTP_REFERER']with PHP, but it's not working correctly and I read that does not work on all browsers. - Is there any language or php script to get this url, working on all browser correctly?
- 是否可以在进入我的页面之前知道用户访问的最后一个 url?
我已经尝试过$_SERVER['HTTP_REFERER']使用 PHP,但它无法正常工作,而且我读到它不适用于所有浏览器。 - 是否有任何语言或 php 脚本来获取这个 url,在所有浏览器上都能正常工作?
回答by Brad
The HTTP referer header is the only way. This is the data that is given to you in PHP via $_SERVER['HTTP_REFERER'].
HTTP 引用标头是唯一的方法。这是通过 .php 在 PHP 中提供给您的数据$_SERVER['HTTP_REFERER']。
Note that this header will work in most cases. Also note that it can be easily spoofed.
请注意,此标头在大多数情况下都有效。另请注意,它很容易被欺骗。
回答by Simon
Why not add a GET variable to the link on youtube - www.yoursite.com/?referrer=youtube
为什么不向 youtube 上的链接添加 GET 变量 - www.yoursite.com/?referrer=youtube
For discretion and appearance you could rewrite the URL to something like www.yoursite.com/youtube
为了谨慎和外观,您可以将 URL 重写为 www.yoursite.com/youtube 之类的内容

