Delete cookie from browser?

后端 未结 6 1697
野的像风
野的像风 2021-02-19 04:03

Is there any way of instructing a web browser to completely delete one\'s cookie set with PHP?

I do not want to expiry it or wait for the brows

6条回答
  •  广开言路
    2021-02-19 04:11

    'Seems that deleting a cookie is more difficult than it looks.

    setcookie($name, '', 1);
    

    Won't do the trick. The '' is empty and setcookie can ignore the whole instruction.

    Also setting the time to the past sometimes allows the cookie to retain the value whose expire time is newer than 1.

    I am dealing with this right now. I don't know where it comes from, but it's there.

    I've resorted to

    setcookie($name, '0', 9000000000);
    

    This ensures the cookie is set to a value that resolves to false and that it is newer than any previous value.

    If anyone has any insight into this behavior please tell.

    I suspect the difficulty lies in the fact that the domain and path values for setcookie are guaranteed to be the same from execution to execution when the values are not specified.

    And I am aware such a cookie will not expire until 2038 or so.

    Alternately, if the newest expiration date of the cookie is known, it need be set only 1 second after.

提交回复
热议问题