PHP 会话变量未定义错误
我最近开发的管理网站遇到了一个非常令人沮丧的问题。我将错误处理设置为自己发送电子邮件,并且在系统使用时随机收到多条“错误:[8]未定义索引:用户名”消息。然而,我无法确定触发这些错误的确切操作。此外,当错误处理设置为回显时,这些消息不可见,并且站点的功能不受影响。
在我看来,问题是由会话超时引起的,并且站点没有正确处理此问题。然而,当登录被保留一段时间然后刷新时,它确实会按预期重定向到登录页面,没有错误。
每个页面的最顶部包括:
session_start();
接下来是错误处理代码。接下来是安全代码,其中第一个检查是:
if(isset($_SESSION['loggedin']) and isset($_SESSION['username'])) {
如果失败,则调用 session_destroy();
并重定向到登录页面。
我不明白为什么
> Error: [8] Undefined index: username'
当每个页面的标题中都有资产检查时我仍然不断收到电子邮件!这些错误的不规则性使我无法调试。
任何对可能出现问题的见解将不胜感激! 非常感谢:)
I've been experiencing a very frustrating problem with a administrative website I have recently developed. I have error handling set to email myself, and randomly I receive multiple 'Error: [8] Undefined index: username' messages whilst the system is in use. I have been unable to identify the precise actions that trigger these errors however. Also, these messages aren't visible when error handling is set to echo, and the functionality of the site isn't affected.
It seems to me that the problem was caused by the session timing out, and the site not handling this correctly. However, when a login is left for a period of time then refreshed it does indeed redirect to the login page as expected with no errors.
Included at the very top of every page is:
session_start();
Next is the error handling code. This is then followed by the security code of which the first check is:
if(isset($_SESSION['loggedin']) and isset($_SESSION['username'])) {
if this fails, session_destroy();
is called and it redirects to the login page.
I cannot work out why I still keep receiving
> Error: [8] Undefined index: username'
emails when an isset check is in the header of every page! The irregularity of these errors are making it impossible for me to debug.
Any insight into what might be the issue would be very much appreciated!
Many Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加到您的调试代码中。让您的调试电子邮件在文件输出时也向您发送 debug_backtrace 调用的输出。这样您就可以看到从最外层脚本到发生错误的行所采取的确切路径。
Try adding to your debug code. Make your debug emails also send you the output of a debug_backtrace call at the time the file is output. This way you can see the exact path taken to get from the outermost script, to the line where the error is occurring.