Asked 3 years ago
13 Jul 2021
Views 464
Pearline

Pearline posted

Is it possible to destroy a cookie in PHP ?

i am using setcookie to set some cookie but dont know how to delete cookie before it become security issue

Is it possible to destroy a cookie in PHP ?
sec8

sec8
answered Jul 17 '21 00:00

yes it is possible you can either one or all way what i am gonna suggest below:
1. use unset() function to unset the cookie index and their value

$_COOKIE["TestRookie"]='';
unset($_COOKIE["TestRookie"]);


2. set cookie in very past time , so it become noted as expired cookie

setcookie("TestRookie", "1", time()-3600);



so you can use below code collectively with set cookie in past time and unset it value and key in $_COOKIE

$_COOKIE["TestRookie"]='';
unset($_COOKIE["TestRookie"]);
setcookie("TestRookie", "1", time()-3600);
Post Answer