Jump to content

Sessions don't work


judacoor

Recommended Posts

Hey!I've been trying to set a session variable, and it works within the .php file I created it, but when I redirect the user to another page, the session disappears and I don't have any idea why.I programmed the code myself, and when I noticed it wasn't working I tryed using dreamweaver to generate all the code for me, but the same thing happens, once the login is succesfull and the user gets redirected to the other page, the session disappears.So I added the following code to the page I am redirecting validated user to: if (!isset($_SESSION)) { session_start();}and now everything seems to be working ok.So I just wanted to check if everytime you are going to work/include a session variable you have to tell the browser to "start it".Thanks!Oh! and another thing, Session variables don't disappear when you close your browser?

Link to comment
Share on other sites

You need to use session_start on any page where you want to use the session, even if you are only reading the session. The session works by sending a cookie to the browser with the session ID in it. The cookie will be deleted when the browser closes so that the browser no longer has access to that session, and if a certain amount of time goes by without the user doing anything the server will delete the session itself.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...