当浏览器设置“referrer”时在 HTTP 请求标头中?

发布于 2024-11-25 00:15:52 字数 127 浏览 3 评论 0原文

我有一个登录页面,来自不同域的用户被重定向到此页面以实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦年海沫深 2024-12-02 00:15:52

用户可以使用不同的方法访问您的页面:

  1. 通过直接在浏览器的地址栏中输入页面的 URL
  2. 通过单击其他网站指向您网站的链接
  3. 通过重新加载当前页面
  4. 通过在您的网站上提交表单(发送POST 请求返回您的网站)
  5. 通过浏览器的后退/前进按钮导航。
  6. 通过前一页重定向到当前页面。

现在,浏览器在设置引荐来源网址标题字段的方式和时间方面确实有所不同。但作为一般规则,您可以确定在单击链接或提交表单(发布请求)时,他们会设置引荐来源网址字段。此外,如果您通过重定向或链接来到当前页面,浏览器仍会在 F5(页面重新加载)上保留引用标头。

如果您发现引荐来源网址字段为空,这是因为有人知道您的登录页面 URL 并将其直接输入到地址栏中,或者有人已将其添加为书签,因此发送了 GET 请求。

一般来说,您不应该总是期待引用字段,因为它超出了您的控制范围。您应该使用 cookie 或查询字符串,因为它们在您的控制之下。

Users can come to your page using different methods:

  1. By entering the URL of your page, directly into the address bar of the browser
  2. By clicking a link to your site from another site
  3. By reloading your current page
  4. By Submitting a form on your site (sending POST request back to your site)
  5. By navigating through back/forward buttons of your browser.
  6. By being redirected through a previous page to the current page.

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.

肩上的翅膀 2024-12-02 00:15:52

另一件事是,作为浏览器安全设置的一部分,某些用户可能在其浏览器中将引用选项设置为禁用。

the other thing is that some user may have referer option set as disabled in their browsers as a part of browser security settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文