A session had already been started ignoring session_start


This error I got now with my code:
Notice: A session had already been started - ignoring session_start() in nav.php on line 2

This is the script:

if (!session_is_registered('login')) {

What is wronge???

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You have two calls to session_start().

One in this file, and one somewhere else.

You can start a session only once.

You can use (I think);

if(!session_id()) session_start();

Ivo StoykovCommented:
Hello WvR,

> <?
> session_start();
this is a snippet, perhaps you have other stuff above... Make this 1st line



the problem is not with the position of the session_start() otherwise the most common error would be the headers already sent message.

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Ivo StoykovCommented:
Hi Roonaan,

I think that all (especially HTML) stuff shuld be after session_start()


No, because if that where the case/problem then you would have seen the "header already sent" error.

The error clearily states "Session already started".

This can indicate three things:
1. There is a session_start() somewhere else in the code
2. This file is called multiple times, hence causing the session_start to be run multiple times
3. The server is setup to autostart sessions.

Hi all:

I encountered that problem in the past as well. Sometimes it is hard to "not start" a session twice, due to incudes etc.

I found though that it has no impact on the session itself. If it does, please let me know...

My workaround was to simply supress the error. Mybe not clean, but it worked:


I am not sure as to the function of session_is_registered(). It may also initialize a session implicitly. You could also escape it with an @ or you check if a session vaiable is set:

If (!isset($_SESSION['variable_name']))
    // sent to login

Maybe this helps. May not be the best way, just my 2 cents...


Thomas :-)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.