douhuanbai6729 2011-08-31 15:23
浏览 111
已采纳

HTTP_REFERER和位置重定向

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

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

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

What I want to do is capture and log the http_referrer 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?

Please note- I know the http_referrer 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).

  • 写回答

3条回答 默认 最新

  • dongyou6909 2011-08-31 15:33
    关注

    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?

    Good ways to achieve this:

    • 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。