Logout Session - not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thesti
    New Member
    • Nov 2007
    • 144

    #1

    Logout Session - not working

    hi,

    i'm learning and trying to develop a web with php. the logout script of mine seems not working since that after i pressed the logout link. i still get the greeting "welcome, 'username' ".

    this is the script in the logout.php that

    [PHP]
    <html>
    <head>
    <meta http-equiv="refresh" content="1; URL=index.php">
    </head>

    <body>
    <?
    //destroy session and redirect user
    session_start() ;

    session_unset() ;
    session_destroy ();

    //redirect using meta tag
    ?>
    </body>
    </html>
    [/PHP]

    hope someone could help. thx
  • nothing1
    New Member
    • Nov 2007
    • 30

    #2
    this is a quote from http://us3.php.net/session_unset
    You should go there and read more. Also it depends on what php version your using.

    sometimes you might have problems even if using both session_unset and session_destroy . You have to clear the $_SESSION array. I got it working this way:

    [PHP]session_unset() ;
    session_destroy ();
    $_SESSION = array();[/PHP]
    Last edited by pbmods; Dec 24 '07, 04:58 PM. Reason: Fixed link.

    Comment

    • thesti
      New Member
      • Nov 2007
      • 144

      #3
      hi,
      thx nothing

      well, it works if i use html form as the logout method. the problem just that i don't want to display the logout as a submit button. i want it to be displayed as a link

      is there any work around..

      thx

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Thesti.

        What happens if you refresh index.php after logging out? You might just be seeing a cached version of index.php.

        Comment

        • thesti
          New Member
          • Nov 2007
          • 144

          #5
          hello,

          after some changes, it works well with FF and IE. but it doesn't work with Opera. even after i refresh the page. can i solve this problem?

          thx

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Thesti.

            Try redirecting to index.php?logge dout=true. The loggedout=true part wouldn't affect your logic, but it would prevent the browser from serving the cached version of the page because "index.php" != "index.php?logg edout=true".

            Comment

            • thesti
              New Member
              • Nov 2007
              • 144

              #7
              i've tried your suggestion to use GET method, but still it doesn't work with Opera. i also have tried to use the no-cache and last-modified things but that doesn't solve the problem too

              wonder if this only happen to me. still working to solve this...

              Comment

              • grimjoey
                New Member
                • Dec 2007
                • 1

                #8
                JS workaround for the submit button to show as link:
                [code=html]
                <form action="" method="post">
                <input type="hidden" name="logout" value="true" />
                <a href="#" onclick="docume nt.getElementBy Id('submitbutto n').click();">L ogout</a>
                <input id="submitbutto n" type="submit" name="submit" value="test" style="display: none;">
                </form>[/code]
                Last edited by pbmods; Dec 25 '07, 05:57 PM. Reason: Added CODE tags.

                Comment

                Working...