tags:

views:

44

answers:

2

HEY GUYS

deleting cookie is a easy thing to do in php but problem is untill i get out of my browser it still exists

setcookie("PHPSESSID", false);
setcookie("PHPSESSID","",time()-31536000); 

any way to delete this cookie whithout need of closing the browser ?!

so what do u think ?!

+1  A: 

Properly destroy the session and set the session cookie var to expire in the past.

From the PHP.net manual on session destroy:

    <?php
// Initialize the session.
// If you are using session_name("something"), 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 (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();
?>
DBQ
session_destroy() function was what i was looking for ... .thanks to jog my memory
Mac Taylor
+2  A: 

Cookie headers are only sent as soon as the user laods a new page. So just unsetting the browser server side will not delete it on the client.

Also be aware of the domain. You should always use a fourth parameter to set a cookie for all paths on your site. If you don't do that, a cookie from a subfolder might still exists.

You can check with cookies are set using some JavaScript function or the Web Developer Toolbar for Firefox.

Kau-Boy