views:

67

answers:

3

Hello

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.

+1  A: 

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.

Josh Curren
as in put session_start in an if statement?
YsoL8
I dont think session_start needs to be, but any session vars you are setting need to be.
Josh Curren
A: 

Cookies enabled? You can also pass the session_id via the request (url).

Martin
+1  A: 

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

Rob