Forgive me, my php is a little rusty. I'm trying to do a simple login form but every time I refresh the page, I get a new session id. Here's the code, every time I click login, I get a different session id. Any ideas why?
The session ID is the unique identifier to tell the server to load data from the associated session file.
Presumably, every time you hit login, it's after you've logged out - and I assume you're logging out with a call to session_destroy()?
session_destroy would completley erase your session, so the login would cause the server to create a new session with another identifier, and create a cookie on your machine with the new identifier - your session id.
I'm not calling anything. You can literally copy that code and put it in a php file. I understand how sessions work and what not, I've just been developing in .net for the last 5 years so it's been a while. The only thing I'm doing on that right now is trying to output the session id and connect to my db. I even removed the connect() line and I still get a new session id every time. I have no idea why it would be getting destroyed and re created every time I hit a submit button.
Ok, it has to be something stupid but why in the hell am I getting a new session id each time. I simplified my page to this and every time I click the button, I get a new session id. Here is the simplified code.
Do you by any chance use php 5.3? There is a similar problem mentioned in official php site here [php.net]. The problem is that you use session_id() after session_start() (if i understand the situation correctly)
Edit: if you put your session_start() at the very top of your page, your ssession_id() maintains its value (tested in 5.1.4 and 5.3.3)
[edited by: omoutop at 1:05 pm (utc) on Sep 20, 2013]
Holy crap, thanks! I never, ever would have figured that out. Any ideas on how to convert the files? I don't see how I would do that in notepad++. What I ended up doing was deleting one and creating a new text file with notepad++.