how to destroy sessions in php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pran
    New Member
    • Apr 2008
    • 3

    how to destroy sessions in php?

    I have written 3 php scripts for user login, mainpage and logout. When the user submits the login form it athunticates the user, if he is a valid user then it will redirect the user to main page. In the main page i have used the href tag for logout which unsets the user session. After user logged out if he presses 'back' navigator button on the browser page then it is showing the mainpage which should not be shown after user logout. How to handle this?


    thanks in advance
  • Ranjan kumar Barik
    New Member
    • Aug 2007
    • 95

    #2
    Originally posted by pran
    In the main page i have used the href tag for logout which unsets the user session.
    If your session unsets with logout then you check for session variable on top of page;

    [PHP]isset($_SESSION['your name']);[/PHP]

    If not set, then redirect him to login page.

    :))

    Comment

    • pran
      New Member
      • Apr 2008
      • 3

      #3
      Originally posted by Ranjan kumar Barik
      If your session unsets with logout then you check for session variable on top of page;

      [PHP]isset($_SESSION['your name']);[/PHP]

      If not set, then redirect him to login page.

      :))

      Thanks for the reply. I did the same thing as you said but it is not working. The same script is working fine with Mozilla Firefox both on the server and client environment. But when i tried with IE7 the script is working fine in the server but in the client it is showing the main page. The script is not revalidating when i am pressing back navigator in the client IE7 browser .


      Here is my code for main page.php:

      Code:
      <?php session_start();// start the session
      // is the one accessing this page logged in or not?
      if (!$_SESSION['is_logged_in'] == 1 )
      {
      	// not logged in, move to login page
          header('Location: login1.php');
          exit;
      }
      else
      {
      ?>
      <html>
      <head>
      <title>Main User Page</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>
      
      <body>
      <p>This is the main application page. You are free to play around here since you
      are an autenthicated user :-) </p>
      <p>&nbsp;</p>
      <p><a href="logout.php">Logout</a> </p>
      </body>
      </html>
      <?php
      }?>

      Here is my code for logout.php:

      Code:
      <?php
      session_start();
      // if the user is logged in, unset the session
      if (isset($_SESSION['is_logged_in']))
      {
         unset($_SESSION['is_logged_in']);
      }
         unset($_SESSION);
         if (isset($_COOKIE[session_name()])) {
          setcookie(session_name(), '', time()-42000, '/');
      }
      session_destroy();
        
      // now that the user is logged out,
      // go to login page
      header('Location: login1.php');
      
      ?>

      Comment

      • mageswar005
        New Member
        • Mar 2008
        • 72

        #4
        hi,
        please go and see the below link,

        http://php.about.com/od/phpfunctions/g/session_unset.h tm

        regards
        mageswaran

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          I believe - if i understand the problem - IE is showing you a cached version of the page; this can't be countered.. but as soon as the client does anything with the browser the page will be forced to refresh.

          Comment

          • pran
            New Member
            • Apr 2008
            • 3

            #6
            Originally posted by markusn00b
            I believe - if i understand the problem - IE is showing you a cached version of the page; this can't be countered.. but as soon as the client does anything with the browser the page will be forced to refresh.

            The page is not refreshing even after client does anything with the browser. I have tried no-cache but that too is not working.

            Code:
            META HTTP-EQUIV="Pragma" CONTENT="no-cache">
            <META HTTP-EQUIV="Cache-Control" CONTENT="no-store, no-cache, must-revalidate">
            <META HTTP-EQUIV="Cache-Control" CONTENT="post-check=1, pre-check=2">
            <META HTTP-EQUIV="Expires" CONTENT="-1">

            How can i force the browser to refresh on back button hit? or
            How can i make the browser not to store the page in the cache?
            I am getting this problem only with IE and the version i am using is IE7.

            Comment

            Working...