Session persistence problem
I'm having a problem with getting sessions to persist, and having no luck searching, I need to ask.
I can access the contents of my session as expected when first set, but as soon as the page refreshes I lose everything and I don't see why. session_start()
is set and I'm not unseting or destroying anything. I looked at PHP Info under sessions and everything looks ok (but my understanding of sessions is limited).
I'm running MAMP on OS 10.5, and the last time I开发者_运维百科 used sessions they worked.
as Josh has said, you'll want to check for the sessions existence first before you start making a new one, use an if statement to check for the $_SESSION variable, that should give you the results you want. a lil debugging trick i use is to do this:
if($_SESSION) {
echo 'session exists';
else {
echo 'does not exist';
}
This way i know instantly what code block is being called, without worrying about whats contained inside.
Hope this helps :)
If you are refreshing the page you may be creating a new session and/or overwriting the session variables. You should check if a session variable is already set before setting it.
Cookies enabled? You can also pass the session_id via the request (url).
精彩评论