A session had already been started ignoring session_start

Posted on 2006-04-21
Last Modified: 2008-03-20

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???

Question by:WvR
    LVL 49

    Expert Comment

    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();

    LVL 22

    Expert Comment

    by:Ivo Stoykov
    Hello WvR,

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


    LVL 49

    Expert Comment


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

    LVL 22

    Expert Comment

    by:Ivo Stoykov
    Hi Roonaan,

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


    LVL 49

    Expert Comment

    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.


    Accepted Solution

    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 :-)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now