Home php PHP: why not delete cookie

PHP: why not delete cookie

Author

Date

Category

If I prescribed in php code is:

setcookie ( "Hello", "Hello!");
echo $ _COOKIE [ "Hello"];

And it displays Hello!

But after I ordered

unset ($ _ COOKIE [ "Hello"]);
echo $ _COOKIE [ "Hello"];

And I do not become the norm brought Hello! And after I removed the unset has brought me back Hello! How to kill the cookies that he would not again see a large?


Answer 1, Authority 100%

If you do not specify cookie lifetime, then it becomes a session and is valid until such time as the user does not shut down the browser. Destroy it only on the server useless to force the browser to delete it and not send more using HTTP-heading Set-Cookie.

Therefore, in order to destroy the session cookie it is necessary to set the lifetime coincides with the current or an earlier time – in this case, the browser destroys it on its side and will not send HTTP-header Set-Cookie, which initializes the value in the array $ _COOKIE

setcookie ( "Hello", "", time () - 100);

Answer 2, Authority 40%

Because $ _COOKIE – it Superglobals only. and you delete it. Instead of cookies explorer.

What would delete browser cookies, you need to install them last time.


Answer 3, authority 20%

To set the cookies in your browser, you must add the time of her life.

If the time expires, the browser itself will remove it.
In order not to wait for the expiration of the time, you can set the -1

setcookie ( "Hello", "Hello", time () + 3600, '/');
setcookie ( "Hello", null, -1, '/');

Answer 4, authority 20%

Open cookie

$ hello = 'Hello!';
setcookie ( 'hello', $ hello, 2147483647, '/');
echo $ hello;

Close cookie

setcookie ( 'hello', $ hello, -2147483647, '/');
echo $ hello;

Answer 5

Already found thanks to all))))

setcookie ( "Hello", "", time () - 3600);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions