Php session cookie

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tusharthakar
    New Member
    • Feb 2010
    • 2

    Php session cookie

    I have this program created in PHP using MVC pattern.

    I am using sessions for the program.

    I am starting the session in bootstrap which is straight after the index.php

    the session name is changed before starting session in bootstrap ... getting to the question after slight more info.

    I wanted to know how to delete session cookie.

    when someone logs in a session is created with specific name

    when they logout I use this code to log the user out

    Code:
    class LogoutController
    {
        public static function logout()
        {
            // 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 (ini_get("session.use_cookies")) 
            {
                $params = session_get_cookie_params();
                setcookie(  session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]
                         );
            }
            // Finally, destroy the session.
            session_destroy();
            header("location:login.php");
        }
    }
    ?>
    when the user is relocated to the login.php page and the user logs in it creates another session cookie with the same name. I know this because I checked this on Mozilla firefox's cookie browser.

    i dont know if I'm taking the right steps.

    please help pplz
  • helimeef
    New Member
    • Sep 2007
    • 77

    #2
    Get rid of the if() statement, and just leave the code that's inside it. setcookie() is the only way to permanently delete session data, and your condition may not be getting evaluated as true.
    Then, let us know if it worked or not.

    Comment

    Working...