简体   繁体   English

如何在PHP的Cookie中存储外部HTTP_REFERER以供以后检索?

[英]How to store an external HTTP_REFERER in a cookie in PHP for later retrieval?

I would like to have a PHP code to do the following: 我想要一个PHP代码来执行以下操作:

  • User comes to my website from a link in an external website, in other words, the HTTP_REFERER is not from my own domain. 用户从外部网站上的链接进入我的网站,换句话说,HTTP_REFERER不是来自我自己的域。

  • Save this HTTP_REFERER in a cookie 将此HTTP_REFERER保存在Cookie中

In another part of my website I will check to see if this cookie is present and include the saved referer with the user profile. 在我网站的另一部分中,我将检查该cookie是否存在,并在用户个人资料中包括保存的引荐来源网址。

Saving cookies is pretty easy (see PHP Cookies for details). 保存cookie非常简单(有关详细信息,请参见PHP Cookies )。

if(isset($_SERVER['HTTP_REFERER'])) {
    setcookie("externalRefer", $_SERVER['HTTP_REFERER'], time()+3600);
}

Retrieving is just as easy: 检索同样简单:

if (isset($_COOKIE['externalRefer'])) {
    echo $_COOKIE['externalRefer'];
}

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

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