Delete cookie from browser?

后端 未结 6 1715
野的像风
野的像风 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条回答
  •  猫巷女王i
    2021-02-19 04:26

    You cannot force the browser to delete the file associated with any cookie, because you can't guarantee there's actually such a file - the contract between browser and web server regarding cookies is that the data will be presented at eligible requests.

    You state that you "don't want to wait for the cookie to expire", but cookie expiration is the correct method for indicating that the data is no longer needed and should not be presented on future requests, which in most cases does translate to the browser removing the file.

    To delete a cookie, therefore, set its expiration time into the past. In PHP, this is done with setcookie().

提交回复
热议问题