0

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 1

1

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();
}
Sign up to request clarification or add additional context in comments.

3 Comments

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."
@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..
but yes you'll get an error notice, since calling it multiple times does not make sense

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.