如何使用 PHP 获取用户来自的引荐网站并到达我的网站?
我正在尝试创建在我正在开发的网站上提供促销代码的功能。此功能的一部分要求我获取用户来自的引用网站,以便为他们提供适当的促销代码。
我正在考虑使用它
$_SERVER['HTTP_REFERER']
来获取引用网站,但阅读了此内容
“HTTP_REFERER”
页面的地址(如果有) 将用户代理引用到当前 页。这是由用户代理设置的。 并非所有用户代理都会设置此项,并且 有些提供修改的能力 HTTP_REFERER 作为一项功能。简而言之, 它确实不能被信任。
这似乎不是最好的方法,或者确实如此。有没有更好的方法来获取用户来自并登陆我的网站的网站。
I am trying to create the ability to have promo codes on the site that I am working on. Part of this functionality requires me to get the referring site the user came from to give them the appropriate promo code..
I was thinking of using
$_SERVER['HTTP_REFERER']
to get the referring site but reading this
'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. In short,
it cannot really be trusted.
It seems like not the best approach or is it. Is there a better way to get the site the user came from and landed on my site.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您无法控制用户来自的页面,恐怕
HTTP_REFERER
是唯一的,因此也是查找引用页面的最佳方法。没有比这更值得信赖的了。您可以在 GET 字符串中使用引用者代码,但这也可能很容易被操纵甚至无意中复制。
If you can't control the page the user is coming from, I'm afraid
HTTP_REFERER
is the only, and thus the best approach to find out a referring page.There are none that are more trustworthy. You could use a referrer code in the GET string, but that could be manipulated or even inadvertently copied just as easily.
如果引荐来源网址是您自己的服务器上的页面,您可以使用会话来确定用户访问的最后一个页面。
如果您正在寻找外部推荐,
$_SERVER['HTTP_REFERRER']
是您唯一的选择。If the referrer is a page on your own server, you could use a session to determine the last page the user visited.
If you are looking for external referrals,
$_SERVER['HTTP_REFERRER']
is your only course of action.如果您希望能够依赖它们来自哪个网站,并且您正在处理一组已知的可能的引荐来源网址,您可以安排各种可能的网站,让它们在 URL 中添加一个代码,以指示链接的位置来自。当然,这要求相关网站更像是合作伙伴;谷歌不会与你达成协议。
HTTP_REFERER相对容易被欺骗;如果您正在工作的网站足够突出,或者促销代码足够有价值,人们很可能通过欺骗引荐来源网址(如果您依赖 HTTP_REFERER)来“窃取”促销代码。
If you want to be able to rely on what site they came from, and you're dealing with a known set of possible referrers, you might arrange with the various possible sites for them to add a code to the URL that indicates where the link came from. This requires, of course, that the sites in question are more like partners; Google isn't going to make a deal with you.
HTTP_REFERER is relatively easy to spoof; if the site you're working on is prominent enough, or the promo codes are valuable enough, people may well "steal" the promo codes by spoofing the referrer (if your rely on HTTP_REFERER).