16

Possible Duplicate:
PHP sessions that have already been started

I have run a my PHP project on windows and also Mac with same code . But I got this error when I run my project in windows not in Mac.

error message is .

A session had already been started - ignoring session_start()

which is come only on Windows system. But In Mac I didnt get any error message. Please any one give me a solution .....

Community
  • 1
  • 1

4 Answers4

45

You said that you starts session with a check:

if(!isset($_SESSION)){
    session_start();
}

The fact is the $_SESSION always exists and if you aren't put something in it then it will be always empty, so the statment will return always true.

Peter Kiss
  • 9,309
  • 2
  • 23
  • 38
  • Thanks! I used PHP 5.6 for developing ( used session_status() for checking session) but on server only supports to PHP 5.3 so I got it fixed simply by your answer. – Harsha May 03 '15 at 14:18
5

I didnt know why windows shows the error and Mac dont. But You can try to replace all the session_start() by

if(!isset($_SESSION)) 
    { 
        session_start(); 
    } 

This will may help you..

Sridhar
  • 2,228
  • 10
  • 48
  • 79
5

This message is an E_NOTICE. The reason you're only seeing it on the Windows machine is most likely because you have error_reporting set differently.

If you search php.ini for error_reporting you should exclude E_NOTICE if you don't want to see it.

Alternatively, fix your code to not start a session more than once. Ideally, you would only have one core code file that would start your session and no other instances of session_start() (ie. don't put it on each page). You can then include this on each page, or create a routing pattern that will ensure initialisation code is called on each pageload.

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
0

Have a look at session.auto_start in your php.ini (http://php.net/session.auto-start), most likely the session is automatically started

Rainer.R
  • 458
  • 2
  • 8