Session termination issue

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

    #1

    Session termination issue

    Hi,

    I'm trying to tweak the logout script on my web projects. When I point
    users to a logout.php page containing the session_destroy () function, I
    get the "Trying to destroy uninitialized session" error.

    Any ideas?

    Thanks.

  • Bent Stigsen

    #2
    Re: Session termination issue

    TristaSD wrote:[color=blue]
    > Hi,
    >
    > I'm trying to tweak the logout script on my web projects. When I point
    > users to a logout.php page containing the session_destroy () function, I
    > get the "Trying to destroy uninitialized session" error.[/color]

    Gets initialized with "session_st art"

    See the example:


    --
    /Bent

    Comment

    • TristaSD

      #3
      Re: Session termination issue

      I tried to follow php.net manual to the best of my ability, but I'm
      getting two errors now:

      Warning: session_start() : Cannot send session cache limiter - headers
      already sent
      Warning: Cannot modify header information - headers already sent by

      All I want to do is create a login page that starts the session, and a
      logout page that destroys the session. I'm having a hell of a time.

      Comment

      • Geoff Berrow

        #4
        Re: Session termination issue

        Message-ID: <1150645209.331 434.17340@f6g20 00cwb.googlegro ups.com> from
        TristaSD contained the following:
        [color=blue]
        >I tried to follow php.net manual to the best of my ability, but I'm
        >getting two errors now:
        >
        >Warning: session_start() : Cannot send session cache limiter - headers
        >already sent
        >Warning: Cannot modify header information - headers already sent by
        >
        >All I want to do is create a login page that starts the session, and a
        >logout page that destroys the session. I'm having a hell of a time.[/color]
        Logout.php
        <?php
        session_start() ;
        session_destroy ();
        header("Locatio n: login.php");
        exit;
        ?>




        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Bent Stigsen

          #5
          Re: Session termination issue

          TristaSD wrote:
          [color=blue]
          > I tried to follow php.net manual to the best of my ability, but I'm
          > getting two errors now:
          >
          > Warning: session_start() : Cannot send session cache limiter - headers
          > already sent
          > Warning: Cannot modify header information - headers already sent by[/color]

          Make sure you don't have any output before calling session_start. Not even a
          space or a newline.
          [color=blue]
          > All I want to do is create a login page that starts the session, and a
          > logout page that destroys the session. I'm having a hell of a time.[/color]

          You'll get there. Just remember that session_start needs to be called in all
          pages that uses the session-functions or access the session data.

          --
          /Bent

          Comment

          • David Haynes

            #6
            Re: Session termination issue

            TristaSD wrote:[color=blue]
            > I tried to follow php.net manual to the best of my ability, but I'm
            > getting two errors now:
            >
            > Warning: session_start() : Cannot send session cache limiter - headers
            > already sent
            > Warning: Cannot modify header information - headers already sent by
            >
            > All I want to do is create a login page that starts the session, and a
            > logout page that destroys the session. I'm having a hell of a time.
            >[/color]
            Post your code. It's the fastest way to get help.

            In general, your problem is that some character data (could be as simple
            as a blank or carriage-return) is being sent before your session_start() .

            -david-

            Comment

            • David Haynes

              #7
              Re: Session termination issue

              Geoff Berrow wrote:[color=blue]
              > Message-ID: <1150645209.331 434.17340@f6g20 00cwb.googlegro ups.com> from
              > TristaSD contained the following:
              >[color=green]
              >> I tried to follow php.net manual to the best of my ability, but I'm
              >> getting two errors now:
              >>
              >> Warning: session_start() : Cannot send session cache limiter - headers
              >> already sent
              >> Warning: Cannot modify header information - headers already sent by
              >>
              >> All I want to do is create a login page that starts the session, and a
              >> logout page that destroys the session. I'm having a hell of a time.[/color]
              > Logout.php
              > <?php
              > session_start() ;
              > session_destroy ();
              > header("Locatio n: login.php");
              > exit;
              > ?>[/color]

              My logout is a little more involved:

              <?php
              require_once('a utoload.inc');
              require_once('r edirect.inc');

              session_start() ;

              $sessionName = session_name();
              $sessionCookie = session_get_coo kie_params();

              session_destroy ();

              setcookie($sess ionName, false, $sessionCookie['lifetime'],
              $sessionCookie['path'], $sessionCookie['domain'],
              $sessionCookie['secure']);

              redirect('/ctrl/login.ctrl.php' );
              ?>

              -david-

              Comment

              • TristaSD

                #8
                Re: Session termination issue

                Thanks, all. It seems to work now, but some things are still very odd.
                For example, when I go to www.mysite.com/session, I get "session
                doesn't exist". When I refresh, however, I get the session id. I get
                the session ID when I go to www.mysite.com/session/index.php directly.
                Is it a default page issue? Why is the session started when I go to
                index.php, but not /session/ ?

                Here's the code:

                *** index.php ***
                <?session_start ();?>
                <html>
                <head>
                <meta http-equiv="content-type" content="text/html; charset=UTF-8">
                <title>Sessio n Testing</title>
                </head>

                <body>
                <? echo ($PHPSESSID ? "Session $PHPSESSID exists. You can now <a
                href=\"logout.p hp\">log out</a>." : "Session does not exist."); ?>
                </body>
                </html>

                *** logout.php ***
                <?session_start ();
                session_destroy ();
                //header("Locatio n: index.php");
                echo "Session destroyed.";
                exit;?>

                <html>
                <head>
                <meta http-equiv="content-type" content="text/html; charset=UTF-8">
                <title>Sessio n Destrustion</title>
                </head>

                <body>
                </body>
                </html>

                Comment

                • Nico

                  #9
                  Re: Session termination issue

                  Many "random" errors on php sessions are caused when tring to read the
                  same file from two different process (and one has the session's file
                  locked).
                  Have you tried closing the session for output (leaving it open only for
                  reads) with session_write_c lose()? I solved many session issues witht
                  this.

                  PS: I don't remember the exact function name

                  Comment

                  Working...