LoginModel::deleteCookie PHP Method

deleteCookie() public static method

that's obviously the best practice to kill a cookie @see http://stackoverflow.com/a/686166/1114320
public static deleteCookie ( string $user_id = null )
$user_id string
    public static function deleteCookie($user_id = null)
    {
        // is $user_id was set, then clear remember_me token in database
        if (isset($user_id)) {
            $database = DatabaseFactory::getFactory()->getConnection();
            $sql = "UPDATE users SET user_remember_me_token = :user_remember_me_token WHERE user_id = :user_id LIMIT 1";
            $sth = $database->prepare($sql);
            $sth->execute(array(':user_remember_me_token' => NULL, ':user_id' => $user_id));
        }
        // delete remember_me cookie in browser
        setcookie('remember_me', false, time() - 3600 * 24 * 3650, Config::get('COOKIE_PATH'), Config::get('COOKIE_DOMAIN'), Config::get('COOKIE_SECURE'), Config::get('COOKIE_HTTP'));
    }

Usage Example

Ejemplo n.º 1
0
 public static function initialize()
 {
     if (self::$initialized) {
         return;
     }
     self::$initialized = true;
     try {
         // Initialize local session
         Session::init();
         if (!empty($_GET['logout'])) {
             self::destroy();
             Session::init();
         }
         if (!Session::userIsLoggedIn() && Request::cookie('remember_me')) {
             if (!LoginModel::loginWithCookie(Request::cookie('remember_me'))) {
                 LoginModel::deleteCookie();
             }
         }
         $currentUrl = $_SERVER['REQUEST_URI'];
         $end = strpos($currentUrl, '?');
         if ($end === false) {
             $end = strpos($currentUrl, '#');
         }
         if ($end !== false) {
             $currentUrl = substr($currentUrl, 0, $end);
         }
         // Initialize Facebook session
         /*self::$facebookSession = new FacebookSessionWrapper(
             Tools::getBaseUrl() . $currentUrl,
             Tools::getBaseUrl() . '/logout/'
           );*/
     } catch (\Exception $ex) {
     }
 }
All Usage Examples Of LoginModel::deleteCookie