当浏览器设置“referrer”时在 HTTP 请求标头中?
我有一个登录页面,来自不同域的用户被重定向到此页面以实现 SSO。我使用referrer HTTP 标头字段来了解用户来自哪里,因此在成功登录后,我将他/她返回到他/她的原始域。 但有时我的引荐来源网址未设置,而其他时候则已设置。为什么?
I have a login page and users from different domains are redirected to this page for the purpose of SSO. I use the referrer HTTP Header field to know where the user has come from, thus on successful login, I return him/her back to his/her original domain.
But sometimes my referrer is not set, while other times it's set. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用户可以使用不同的方法访问您的页面:
现在,浏览器在设置引荐来源网址标题字段的方式和时间方面确实有所不同。但作为一般规则,您可以确定在单击链接或提交表单(发布请求)时,他们会设置引荐来源网址字段。此外,如果您通过重定向或链接来到当前页面,浏览器仍会在 F5(页面重新加载)上保留引用标头。
如果您发现引荐来源网址字段为空,这是因为有人知道您的登录页面 URL 并将其直接输入到地址栏中,或者有人已将其添加为书签,因此发送了 GET 请求。
一般来说,您不应该总是期待引用字段,因为它超出了您的控制范围。您应该使用 cookie 或查询字符串,因为它们在您的控制之下。
Users can come to your page using different methods:
Now, browsers really differ in how and when they set referrer header field. But as a general rule, you can be sure that on link click, or on submitting a form (post request), they set referrer field. Also if you have come to the current page via a redirect or a link, browser still preserves referrer header on F5 (page reload).
If you see that your referrer field is empty, it's because someone knows your Login page URL and enters that directly into the address bar, or someone has bookmarked it, so sends a GET request.
Generally, you shouldn't always expect the referrer field, because it's outside your control. You should use cookies, or query strings, because they are under your control.
另一件事是,作为浏览器安全设置的一部分,某些用户可能在其浏览器中将引用选项设置为禁用。
the other thing is that some user may have referer option set as disabled in their browsers as a part of browser security settings.