How to use PHP sessions to manage user login / logout

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akila5277uor
    New Member
    • Jun 2007
    • 1

    #1

    How to use PHP sessions to manage user login / logout

    please help me!
    I want to set "session" my admin login page,how do it?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi, and welcome to TSDN!

    You will have to explain your problem a little better than that.
    Maybe show us some code your having trouble with.

    You should also check out this article, where I discuss how to use sessions in PHP.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      I have edited the thread's title to better describe it's contents.
      I have also moved it to the PHP Forums.

      Please read the Posting Guidlines before posting

      Moderator

      Comment

      • sumaabey
        New Member
        • Jun 2007
        • 29

        #4
        Hai,

        please create a session is the loginid and password is correct

        Create a session in login page
        [code=php]
        <?session_start ();
        $sql="select * from tbl";
        if(numrow=1)
        $_SESSION['sessionname']=$row['userid'];
        ?>
        code for Logout page

        <?session_start ();
        session_destory ();
        header("Locatio n:login.php");
        ?>
        [/code]

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by sumaabey
          Hai,

          please create a session is the loginid and password is correct

          Create a session in login page
          [code=php]
          <?session_start ();
          $sql="select * from tbl";
          if(numrow=1)
          $_SESSION['sessionname']=$row['userid'];
          ?>
          code for Logout page

          <?session_start ();
          session_destory ();
          header("Locatio n:login.php");
          ?>
          [/code]
          Using session_destroy () is not a good idea, as it destroys the entire session which can cause 'collateral damage'.

          It is better to know which variables you want to remove, and unset them using the unset() function.
          [code=php]
          unset($_SESSION['sessionvar']);
          [/code]

          Comment

          Working...