Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't Delete cookie in user class with php
    primarykey
    data
    text
    <p>i think my problem is a little weird, ive wrote a little class to log in/out user, entire system is based in MVC pattern, and my libraries are custom and self written, but the problem: when i log in the user with out the $remember flag, no problems, sessions are easily set and unset. but when i activate the $remember and i create a cookie, my logout function does not work, it deletes the session but not the cookie, so cookie remains in browser with complete data, and whenever i reload the page , my class logs me in again because there is a cookie with full authentication details, the problem is with a cookie, i cant send other headers like Location: blah blah from $this->logout; ive tried different ways to unset cookie, but no luck; this is the class:</p> <pre><code>&lt;?php /** * Pars---- * Classified --- Application * * @author Sallar Kaboli (me@sallar.ir) * @copyright Copyright (C) 2009 - 2010 -----CO (dev@------.us) * @package Pars--- * @version 1.0 */ class ParsUser { public $userID = false; private $_p = null; public $userData = null; public function __construct() { $this-&gt;_p = ParsRegistry::getInstance(); if( $this-&gt;_p-&gt;sess-&gt;isVarSet('parsUser') ) { $this-&gt;loadUser($this-&gt;_p-&gt;sess-&gt;getVar('parsUser')); } if( isset($_COOKIE['parsUser']) and !$this-&gt;isLoggedIn() ) { $userFromCookie = unserialize(base64_decode($_COOKIE['parsUser'])); $this-&gt;checkLogin($userFromCookie['username'], $userFromCookie['password'], true, false); } } public function checkLogin($username, $password, $remember = true, $hash = true) { if(!empty($username) and !empty($password)) { $password = $hash ? $this-&gt;_p-&gt;valid-&gt;hash($password) : $password; $qData = array('user' =&gt; $username, 'pass' =&gt; $password); $query = 'SELECT * FROM people WHERE `username` = :user AND `password` = :pass'; $user = $this-&gt;_p-&gt;db-&gt;getRow($query, $qData); if(is_object($user) AND !empty($user-&gt;id)) { $this-&gt;userID = $user-&gt;id; $this-&gt;userData = $user; if( $hash ) { $this-&gt;_p-&gt;db-&gt;execute('UPDATE people SET `last_login` = ? WHERE `id` = ?', array( time(), $this-&gt;userID )); } $this-&gt;loginTheUser($remember); return true; } else { return false; } } else { return false; } } private function loginTheUser($remember = true) { $this-&gt;_p-&gt;sess-&gt;setVar('parsUser', $this-&gt;userID); if( $remember ){ $rememberPeriod = $this-&gt;_p-&gt;conf-&gt;c['cookie_remember_period']; $cookie = array( 'username' =&gt; $this-&gt;userData-&gt;username, 'password' =&gt; $this-&gt;userData-&gt;password ); $cookie = base64_encode(serialize($cookie)); setcookie('parsUser', $cookie, time() + $rememberPeriod/*, '/', $_SERVER['HTTP_HOST']*/); } return false; } private function loadUser($userID){ $user = $this-&gt;_p-&gt;db-&gt;getRow('SELECT * FROM people WHERE `id` = ?', $userID); if( is_object($user) and ( $user-&gt;id == $userID ) ){ $this-&gt;userID = $user-&gt;id; $this-&gt;userData = $user; $this-&gt;_p-&gt;sess-&gt;setVar('parsUser', $this-&gt;userID); return true; } else return false; } public function logout($redirectTo = false) { setcookie('parsUser', '', mktime(12,0,0,1, 1, 1990)); unset($_COOKIE['parsUser']); $this-&gt;_p-&gt;sess-&gt;sessionDrop(); $this-&gt;userData = null; $this-&gt;userID = false; if ( !empty($redirectTo) ){ $this-&gt;_p-&gt;core-&gt;redirect($redirectTo); exit; } } public function isLoggedIn() { //return ( empty($this-&gt;userID) OR !$this-&gt;userID ) ? false : true; if( $this-&gt;userID &gt; 0 and $this-&gt;userID != false and !empty($this-&gt;userID) ) return true; else return false; } public function checkAccess($level) { if($level == 0) { return true; } elseif($this-&gt;isLoggedIn()) { if( $this-&gt;userData-&gt;level &lt;= $level ) { return true; } else { return false; } } else { return false; } } public function getUserData() { $args = func_get_args(); if( empty($this-&gt;userID) ) throw new Exception('User is not loaded.'); if( is_array($args) and count($args) &gt; 0){ foreach( $args as $arg ){ if( !isset($this-&gt;userData-&gt;$arg) ) throw new Exception('Unknown property: &lt;b&gt;' . $property . '&lt;/b&gt;'); else $props[$arg] = $this-&gt;userData-&gt;$arg; } if( count($args) == 1 ) return $props[$args[0]]; else return $props; } else{ $props = $this-&gt;userData; unset($props-&gt;password); return $props; } } } </code></pre> <p>sorry for my english.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload