简体   繁体   English

“request.referer == nil”是否始终意味着直接流量?

[英]Does “request.referer == nil” always mean direct traffic?

When request.referer doesn't return anything, does that always mean that the visitor didn't do the request through a link - ie she somehow manually entered the requested page's address? request.referer没有返回任何内容时,这是否始终意味着访问者没有通过链接执行请求 - 即她以某种方式手动输入所请求页面的地址?

Or are there other cases where request.referer returns nil (granted that the request is successful)? 或者还有其他情况, request.referer返回nil (授予请求成功)?

Short answer: No. 简答:不。

Generally speaking, the referrer - like all other HTTP headers - is user submitted data. 一般来说,引用者 - 与所有其他HTTP头一样 - 是用户提交的数据。 User submitted data should not be trusted. 用户提交的数据不应该受信任。

Off the top of my head I can think of these scenarios, where the referrer wouldn't be set without the user having manually entered the URL. 在我的脑海中,我可以想到这些场景,如果用户没有手动输入URL,就不会设置引荐来源。

There might well be other cases (fx I am not sure how browsers handle referrers when opening links in new windows). 可能还有其他情况(fx我不确定浏览器在新窗口中打开链接时如何处理引用)。

And then there are the cases where the referrer is set, but no user has entered the address; 然后是设置引荐来源但没有用户输入地址的情况; notably bots - especially the referrer-spamming ones. 特别是机器人 - 特别是推荐人 - 垃圾邮件。

I have not verified that but it's always safe not to check nil for blank value but to use blank? 我还没有证实,但它总是安全不检查nil为空值,但使用blank?

request.referrer.blank?

This ensure the case when it's nil or blank string. 这确保了它是零或空白字符串的情况。

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

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