PHP 会话变量未定义错误 [英] PHP Session Variables Undefined Errors

查看:43
本文介绍了PHP 会话变量未定义错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开发的一个管理网站遇到了一个非常令人沮丧的问题.我将错误处理设置为自己发送电子邮件,并且在系统正在使用时随机收到多个错误:[8] 未定义索引:用户名"消息.但是,我一直无法确定触发这些错误的确切操作.此外,当错误处理设置为回显时,这些消息不可见,并且站点的功能不受影响.

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'])) {

如果失败,则调用 session_destroy(); 并重定向到登录页面.

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'

当每个页面的标题中都有 isset 检查时发送电子邮件!这些错误的不规则性让我无法调试.

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 :)

推荐答案

尝试添加到您的调试代码中.使您的调试电子邮件还在输出文件时向您发送 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.

这篇关于PHP 会话变量未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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