Sessions Again

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arnold Shore

    Sessions Again

    In Win32, php4: (I don't have access to the php.ini file.)

    With 'session_start( )', how do I avoid the complaint "PHP Notice: A session
    had already been started" ?
    Without 'session_start( )', I get the "Undefined variable: _SESSION "
    complaint.

    Any hope? (I'll be happy simply to suppress the error message, although I AM
    trying to understand what's behind it.).

    Thanks, all.

    AS



  • Janwillem Borleffs

    #2
    Re: Sessions Again

    Arnold Shore wrote:[color=blue]
    > With 'session_start( )', how do I avoid the complaint "PHP Notice: A
    > session had already been started" ?[/color]

    Normally this happens when the session.auto_st art directive has been enabled
    in the php.ini file while calling session_start() .
    [color=blue]
    > Without 'session_start( )', I get the "Undefined variable: _SESSION "
    > complaint.
    >[/color]

    This should not happen when you do a simple "print_r($_SESS ION)" on top of
    your script and sounds like a configuration problem. Ask your administrator
    about this.
    [color=blue]
    > Any hope? (I'll be happy simply to suppress the error message,
    > although I AM trying to understand what's behind it.).
    >[/color]

    Prepending an at-sign will surpress the notice:

    @session_start( );


    JW


    Comment

    • Alvaro G. Vicario

      #3
      Re: Sessions Again

      *** Arnold Shore escribió/wrote (Sat, 10 Dec 2005 16:36:10 -0500):
      [color=blue]
      > With 'session_start( )', how do I avoid the complaint "PHP Notice: A session
      > had already been started" ?
      > Without 'session_start( )', I get the "Undefined variable: _SESSION "
      > complaint.
      >
      > Any hope? (I'll be happy simply to suppress the error message, although I AM
      > trying to understand what's behind it.).[/color]

      Try this on top of your code:

      ini_set('sessio n.auto_start', '0');

      I haven't tested but may do the trick. In any case, it'd be interesting to
      see the actual code that claims about $_SESSION being undefined, because
      when you start a session twice the exact notice is:

      A session had already been started - ignoring session_start()

      "Ignoring" sounds like, well, no point in using that code :-?

      --
      -+ Álvaro G. Vicario - Burgos, Spain
      ++ http://bits.demogracia.com es mi sitio para programadores web
      +- http://www.demogracia.com es mi web de humor libre de cloro
      --

      Comment

      • Mara Guida

        #4
        Re: Sessions Again

        Arnold Shore wrote:[color=blue]
        > With 'session_start( )', how do I avoid the complaint "PHP Notice: A session
        > had already been started" ?
        > Without 'session_start( )', I get the "Undefined variable: _SESSION "
        > complaint.[/color]
        <snip>

        Maybe you're trying to do session_start() more than once.

        Try this:
        <?php
        echo 'ini_get('sessi on.auto_start') is ',
        ini_get('sessio n.auto_start'), "<br>\n";
        echo 'before session_start() session_id() returns ', session_id(),
        "<br>\n";

        // You may want to replace your session_start() s with this too
        if (!session_id()) session_start() ;

        echo 'after session_start() session_id() returns ', session_id(),
        "<br>\n";
        ?>

        Comment

        Working...