I\'ve tried searching the php manual and internet on how to delete cookies and I\'ve tried it the exact same way they all say:
setcookie(\"name\", \'\', 1);
I had a similar issue.
I found that, for whatever reason, echoing something out of logout.php made it actually delete the cookie:
echo '{}';
setcookie('username', '', time()-3600, '/');
Just like is said in the correct answer (I want it to send an updated one), to unset, every parameter used to set the cookie is necessary, even secure and httponly
Set
setcookie("name_cookie", $name_value, 0, '/', $domain, false, true);
Unset
setcookie("name_cookie", '', time()-1000, '/', $domain, false, true);
I'm surprised no one has mentioned it (or maybe I missed it), but domain is important too! If you are on sub-domain.example.com, and the cookie is from .example.com, then you need to explicitly set the domain parameter, otherwise it will assume the current domain and it won't work.
setcookie('cookiename', FALSE, -1, '/', '.example.com');
Sub-domains value will not clear cookies from parent domain.
Have you tried setting the time to a small value and using a value for cookie?
setcookie("name", 'n', 1);
Ok, I really don't understand, but it works now. The magic code is:
setcookie("name", '', 1, $path);
Haven't I already tried that??! Whatever, it works now. Thanks for your help, people!
var remember = $.cookie('auto_login');
if (remember == 'true') {
var username = $.cookie('username');
var password = $.cookie('password');
$('#username').val(username);
$('#password').val(password);
}
$('#logsub').click(function (event) {
if ($('#auto_login').is(':checked')) {
var username = $('#username').val();
var password = $('#password').val();
// set cookies to expire in 14 days
$.cookie('username', username, {expires: 14});
$.cookie('password', password, {expires: 14});
$.cookie('auto_login', true, {expires: 14});
} else {
// reset cookies
$.cookie('username', null);
$.cookie('password', null);
$.cookie('auto_login', null);
}
});