When request.referer doesn't return anything, does that always mean that the visitor didn't do the request through a link - i.e. she somehow manually entered the requested page's address?

Or are there other cases where request.referer returns nil (granted that the request is successful)?

有帮助吗?

解决方案

Short answer: No.

Generally speaking, the referrer - like all other HTTP headers - is user submitted data. 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.

There might well be other cases (fx I am not sure how browsers handle referrers when opening links in new windows).

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?

request.referrer.blank?

This ensure the case when it's nil or blank string.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top