Jump to content

A session had already been started - ignoring session_start()


Recommended Posts

Hi,

 

I am getting above said error. I have tried the following but no use:

 

if(!isset($_SESSION))

{

}

else

{

session_start();

}

 

and

 

if(!isset(session_id()))

{

}

else

{

session_start();

}

 

Please help...

 

TIA

Anuj Garg

Bricktop, to be descriptive, I am using CodeIgniter and have the statement session_start() at the bottom of the file config.php.

Yes, you are right, this file is being included multiple times on a page.

 

Please let me know what is the solution to get rid of this error.

 

TIA

Anuj

Hi anujgarg,

 

You could simply use @session_start(), the @ would suppress the error but obviously there is still an error occuring and this isn't ideal.

 

if(!isset($_SESSION)) is the correct syntax to use when checking if a session has been started.  Try amending the code in your config.php to be:

 

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

 

Then the session will only start if it hasn't already been started.

 

Hope this helps.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.