HTTP_REFERER和位置重定向 [英] HTTP_REFERER and Location redirect

查看:174
本文介绍了HTTP_REFERER和位置重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里找了一段时间,找不到我特定问题的答案.

I have been looking for a while here and can't find an answer to my specific question.

我要在网站上的100多个位置中通过标头位置重定向重定向到错误页面.

In 100's of places on my site I am redirecting to an error page via a header-location redirect.

header("Location: /error.php");

我想要做的是捕获HTTP_REFERER并将其记录在error.php页面上,但是由于某种原因未设置它.我已经看到了为什么没有使用Meta-refresh设置它的解释,但是location标头是302,所以应该正确设置它吗?有什么想法吗?

What I want to do is capture and log the HTTP_REFERER on the error.php page, but for some reason it isn't set. I have seen explanations of why it isn't set with Meta-refresh, but the location header is a 302, so it should be set right? Any thoughts?

请注意:我知道HTTP_REFERER不可靠,并且我知道可以单独传递信息.在我的方案中,这都不重要(除非我想更改重定向的所有调用位置.)

Please note: I know the HTTP_REFERER is unreliable, and I know that I can pass the information separately. Neither of which matter in my scenario (unless I want to change all the places where the redirect is called).

推荐答案

好吧,HTTP_REFERER是由浏览器设置的,如果浏览器选择不将其设置为302重定向,则不应这样做,那么您将不会明白了. 302是一个临时重定向,这意味着上一页暂时不可用.浏览器为什么要发送当前不存在的页面的信息?

Well, the HTTP_REFERER is set by the browser and if the browser chooses not to set it on a 302 redirect, which is shouldn't, then you won't get it. A 302 is a temporary redirect, which means the previous page is temporarily unavailable. Why would the browser want to send information for a page that doesn't exist right now?

实现此目标的好方法:

  • 个人而言,我有一个Errors类来处理这种类型的东西,而不是直接从页面重定向.这样,您甚至可以在重定向发生之前记录所需的所有信息,甚至调试信息.
  • 设置一个包含页面信息的会话,并在错误页面上获取该信息以进行记录.
  • 您可以尝试使用标头设置Referer行,但是某些浏览器会忽略此行,也不会发送.
  • Personally, I have an Errors class that handles this type of stuff, rather than just redirecting straight from the page. This allows you to record all the information you need, even debug information, before the redirect even occurs.
  • Set a session that includes the page information and grab that information on the error page for recording.
  • You can try to set the Referer line using header, but some browsers ignore this and will not send it anyways.

真的,如果不修改您也要为其记录信息的每个重定向位置的代码,就无法解决此问题.

Really there is no way to fix this without modifying the code at each and every place where it's redirected that you also want to record information for.

这篇关于HTTP_REFERER和位置重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆