I have a PHP page that has session_start() at the very top. Halfway through the page, if a certain condition is met, the page is reloaded using JavaScript. I'm wondering if session_start() is called again when the page is reloaded or does PHP know to skip it since the session has already started?
1 Answer
session_start — Start new or resume existing session. Starts a new session if not started else resumes the existing session.
Added You could check and initiate, like:
if (session_id() == "") {
session_start();
}
3 Comments
heron1000
That page says, "As of PHP 4.3.3, calling session_start() after the session was previously started will result in an error of level E_NOTICE. Also, the second session start will simply be ignored."
Sudhir Bastakoti
@Bryan as per your question, since you already have session_start() at top of page so if you have second session_start() somewhere in mid of page, that will get ignored and your previous session will resume..
Sudhir Bastakoti
but yes you'll get an error notice, since calling it multiple times does not make sense