Warning: session_destroy(): Trying to destroy uninitialized session with phpCas

你离开我真会死。 提交于 2019-12-12 02:31:38

问题


I am facing a problem today with the phpCas library https://wiki.jasig.org/display/CASC/phpCAS.

Problem is the following, when I try to use some logout function, I got the message

Warning: session_destroy(): Trying to destroy uninitialized session

After giving a quick look into the phpCas's library code, I manage to figure out where the problem comes from, here is a snippet of a logout function :

session_write_close();
header('Location: '.$cas_url);
phpCAS::trace("Prepare redirect to : ".$cas_url);
session_unset();
session_destroy();

The problem there it seems is that session_write_close() actually close the session then session_destroy() can't work.

Tried to put the session_write_close() in comment and worked like a charm but it leads to two questions :

  • Is the problem really coming from there? Or should it work?

  • If the problem do really come from there, why is it there and nobody complaining? Thought phpCas was a reknown library used by many.


回答1:


Sounds like you checked out the master branch (2af859ff76) - just checked and it does have an error in it. You should:

  • Check out one of the release branches, like 1.3-stable
  • Log this bug with the author



回答2:


As the manual suggests that "session_write_close — Write session data and end session" So you are getting fair warning. as Session has been closed already.

FYI




回答3:


you need session_start(); before you can destroy it

also header("Location ...) is sending out headers so you can't close the session afterwards. do the redirect after closing the session



来源:https://stackoverflow.com/questions/17522574/warning-session-destroy-trying-to-destroy-uninitialized-session-with-phpcas

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