Related
Sessions – Sessions and Statefullness
Sessions – Sessions are Stateful, PHP user code is not
Sessions – Where to use session_start()
Sessions – Statefullness and Runs
PHP.net
Specefic Two ID issue
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is visible in the PHP sourcecode for the
session_startfunction. You need to read the C-code and compare with your usage.From what I know about sessions,
session_startwon’t start a new session if already one is active. To find out if a session is already active, please see How to tell if a session is active?.However if a session is started (and it didn’t existed earlier) and then closed and you create a new session in the same request, PHP might think that the session does not exists (because the cookie from the browser is still empty). So then a second, also new, session will be started.
If you’re unsure what does what, just create yourself a test script where you play around with scenarios.
A possible scenario:
session_start()is called. No session cookie exists, PHP will create a new session id and will create cookie headers.session_start()is called. No session cookie exists (in the request), PHP will create a new session id and will create cookie headers.Two sessions have been created of which one will not be used by the browser for subsequent requests (the session id header for the cookie has been “overwritten” (the last cookie header replaces previous ones for the cookie in question).
To debug things,
headers_listcan be useful as well as$_COOKIES.