If I wrote this in php code:

setcookie("Hello", "Привет!"); echo $_COOKIE["Hello"]; 

And it brings me Hi!

But after I prescribed

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

And everything became the norm I did not bring Hi! And after I removed the unset I again brought Hi! How to kill cookies so that it would not appear again more?

    5 answers 5

    If you don’t set a cookie for a lifetime, it becomes a session cookie and is valid until the user turns off the browser. It is useless to destroy it only on the server; you need to force the browser to erase it and not send it again using the Set-Cookie HTTP header.

    Therefore, in order to destroy a session cookie, it needs to set the lifetime to match the current or earlier time - in this case, the browser will destroy it on its side and will not send the Set-Cookie HTTP header, which initializes the value in the $_COOKIE

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

      Because $ _COOKIE is only a superglobal variable. and you delete it. And not the cookie of the breezer.

      And to remove browser cookies, they need to set the past time.

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

        If time expires, the browser will remove it itself.
        To not wait for the time to expire, you can set the time to -1

         setcookie("Hello", "Привет", time() + 3600, '/'); setcookie("Hello", null, -1, '/'); 

          Open cookie

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

          Close cookie

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

            Already found thanks to everyone))))

             setcookie ("Hello", "", time() - 3600); 
            • Why set the time from the current to minus an hour? You need to write correctly, not crutches - Mr. Black