PHP Session Variables Undefined Errors

混江龙づ霸主 提交于 2019-12-11 03:15:27

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/7066507/php-session-variables-undefined-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!