I want to unset/delete my existing cookie with this:
setcookie ("user", "", time()-1);
unset($user);
But cookies can not be deleted or unset. So what is problem?
Nothing - that code looks fine to me.
Quoting the docs:
When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser.
setcookie ("TestCookie", "", time() - 3600);
You may like to specify a time that's more in the past to avoid problems with the computer's time that may be a bit off.
Additionally, in some cases it's useful to actually unset $_COOKIE['TestCookie'] as well.
As already was said - when deleting a cookie you should assure that the expiration date is in the past.
BUT you also have to use the same path and even domain for deleting, which you used for cookie creating, so if create cookie like this
setcookie ("user", "John", time()+7200, '/', 'mydomain.com');
to delete this cookie use this code
setcookie ("user", "", time()-3600, '/', 'mydomain.com');
and also better use specific date in the past instead of time() - 3600
$cookie->delete()helpful, as found in this standalone library. - caw