简体   繁体   English

PHP:标头重定向仅在IE之后,会话似乎丢失了

[英]PHP: session seems to be lost after header redirect only on IE

I can't find a good answer for this anywhere. 我在任何地方都找不到合适的答案。 I have a login page, and after a good login it redirects to main page. 我有一个登录页面,登录成功后,它会重定向到主页。 In FF, and chrome - works perfect. 在FF和chrome中,效果完美。 On IE it doesn't work. 在IE上不起作用。 I keep losing the session when I get to the main page. 进入主页后,我一直在丢失会话。

I have checked the following: - session_start at top - no blanks or anything befoer header redirect - one line before the redirect, IE knows the session user id, but after the redirect, just one line after the session start, it loses the session user id - I've checked it also on other computer - same results 我已经检查了以下内容:-会话开始在顶部-标题之前没有空白或任何内容-重定向前一行,IE知道会话用户ID,但是重定向后,会话开始后仅一行,它将丢失会话用户id-我也在其他计算机上检查过-同样的结果

What is wrong with IE? IE有什么问题? or what could be wrong with my script ? 还是我的脚本可能出什么问题? Thanks 谢谢

  • Set PHP's error_reporting to -1 ; 将PHP的error_reporting设置为-1 reproduce error; 重现错误; check logs 检查日志
  • Check IE's privacy settings-- $_SESSION relies on either a cookie or URL-based session identifier. 检查IE的隐私设置- $_SESSION依赖于cookie或基于URL的会话标识符。 It seems as though it's having trouble saving the cookie 似乎无法保存Cookie
  • Is there anything you're doing to the response that is not standard (eg modifying headers) 您是否正在对非标准响应进行任何处理(例如,修改标头)
  • Can you build an extremely simple version of this code and test it using nothing but the bare essentials (narrow down the problem to a specific bit of code) 您能否构建此代码的极其简单的版本并仅使用基本要点(仅将问题范围缩小至特定的代码)进行测试?

[Edit] [编辑]

  • Make sure you aren't calling session_start() twice ;) 确保您没有两次调用session_start() ;)

Ok, 好,

Problem solved. 问题解决了。 I can't find the logic behind this solution, but although I had session_start() at the top of the page, I added another session_start() just before writing the session vars. 我找不到此解决方案背后的逻辑,但是尽管我在页面顶部有session_start(),但在编写会话变量之前我又添加了另一个session_start()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM