how to end up session

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • exoskeleton
    New Member
    • Sep 2006
    • 104

    how to end up session

    hi there im about to code for a log-out and i try to code this session_destroy ();
    but it wont work...the value of the variable stl there.

    please tell me sir expert on how to design a log out and how to design a no-cache to prevent the user to click back button of the IE going to log in page again after he log in..

    thank you please help
  • exoskeleton
    New Member
    • Sep 2006
    • 104

    #2
    in addtion : i got this message if i write session_destroy

    Warning: Trying to destroy uninitialized session

    Originally posted by exoskeleton
    hi there im about to code for a log-out and i try to code this session_destroy ();
    but it wont work...the value of the variable stl there.

    please tell me sir expert on how to design a log out and how to design a no-cache to prevent the user to click back button of the IE going to log in page again after he log in..

    thank you please help

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      If you want to destroy the variable in the $_SESSION use
      Code:
      unset($_SESSION['var_name']);
      If you want to destroy the entire session, use this code snippet from the PHP documentation http://nl3.php.net/manual/nl/functio...on-destroy.php
      [PHP]<?php
      // Initialize the session.
      // If you are using session_name("s omething"), don't forget it now!
      session_start() ;

      // Unset all of the session variables.
      $_SESSION = array();

      // If it's desired to kill the session, also delete the session cookie.
      // Note: This will destroy the session, and not just the session data!
      if (isset($_COOKIE[session_name()])) {
      setcookie(sessi on_name(), '', time()-42000, '/');
      }

      // Finally, destroy the session.
      session_destroy ();
      ?> [/PHP]

      Ronald :cool:

      Comment

      • exoskeleton
        New Member
        • Sep 2006
        • 104

        #4
        thank you sir...im very thankful for your brillian ideas...one more thing sir...ahmmm...i f i declare the session is it automatic to create a cookie? coz in your sample given you also unset the cookie but i did not declare any cookie..

        i know this is a newbie question ... hope you dont get ... you know.. im just a little confused little fellow coz i dont declare any cookie...

        more power

        Originally posted by ronverdonk
        If you want to destroy the variable in the $_SESSION use
        Code:
        unset($_SESSION['var_name']);
        If you want to destroy the entire session, use this code snippet from the PHP documentation http://nl3.php.net/manual/nl/functio...on-destroy.php
        [PHP]<?php
        // Initialize the session.
        // If you are using session_name("s omething"), don't forget it now!
        session_start() ;

        // Unset all of the session variables.
        $_SESSION = array();

        // If it's desired to kill the session, also delete the session cookie.
        // Note: This will destroy the session, and not just the session data!
        if (isset($_COOKIE[session_name()])) {
        setcookie(sessi on_name(), '', time()-42000, '/');
        }

        // Finally, destroy the session.
        session_destroy ();
        ?> [/PHP]

        Ronald :cool:

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          The code I posted is copied from the PHP documentation and serves as a sample. As you can see the code line
          [PHP]if (isset($_COOKIE[session_name()])) {[/PHP]
          will only delete the cookie if it is set. You can take that code line out or leave it just in case you ever decide to set session cookies.

          Ronald :cool:

          Comment

          • exoskeleton
            New Member
            • Sep 2006
            • 104

            #6
            Thank you very much sir

            Originally posted by ronverdonk
            The code I posted is copied from the PHP documentation and serves as a sample. As you can see the code line
            [PHP]if (isset($_COOKIE[session_name()])) {[/PHP]
            will only delete the cookie if it is set. You can take that code line out or leave it just in case you ever decide to set session cookies.

            Ronald :cool:

            Comment

            Working...