tags:

views:

86

answers:

5

Presumably there's some tiny performance hit, but beyond that?

+1  A: 

As of PHP 4.3.3, calling session_start() while the session has already been started will result in an E_NOTICE warning. The second call to session_start() will simply be ignored.You could check if the session has been started first or not with:

if (session_id() == "")
  session_start();
rkulla
Cite your sources, no one likes plagiarism.
animuson
It's from the PHP docs for session_start(). Hardly plagarism.
rkulla
It is if you don't state that. Especially considering you *slightly* modified it.
animuson
That's because I modified it to show that it was an E_NOTICE 'warning' version to help him avoid confusion since an E_NOTICE could also mean a runtime error. But thanks everyone for shooting my perfectly good answer down. Not to mention i was the first responder. Are you telling me the two answers that followed me had to repeat what I said just to point out the source they got it from? Right. But I'll be extra sure to make sure I site any possible sources next time to avoid wasting my time.
rkulla
Plagiarism? No. 5 people jumping on a question with an easy answer in the docs all within 1 minute of each other? Yes. +1 just to counteract this nonsense.
Syntax Error
+5  A: 

From the docs:

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.

So no, it won't "cause harm", but it'll throw an error. And the fact that it's happening is probably an indicator that you're doing something incorrectly, and might need to re-think how your code is laid out.

Chad Birch
+2  A: 

Reading the docs for session_start, all I can see is:

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.

So, you'll get an E_NOTICE and be ignored.

vicvicvic
A: 

If the session is already open, then it will return an error notice, and the new session will be ignored. So no harm is done, but you will have a pesky error.

But... if you are finding the need to do this then it could be a symptom that your code is not organized well. It would probably be in your benefit to see how you can keep yourself from repeating redundant tasks like starting a session.

Syntax Error
A: 

I usually put a session start statement in an include file that I require_once. But I don't think there should be an issue with multiple calls.

DKinzer