I have this function to set a cookie:
private function setCookie($key, $value){
if(setcookie(
$key,
$this->encrypt($value),
time() + 2592000,
adminpath,
database::getDomain(),
database::getHTTPS(),
true
)){ // set cookie for a month
return true;
}
else{ // cookie could not be created, write to errorlog
$error = array(
"type" => "other",
"argument" => 1,
"class" => __CLASS__,
"function" => __FUNCTION__,
"errorMsg" => "Could not create cookie ".$key." with value ".$value,
"file" => __FILE__,
"line" => __LINE__
);
$this->errorlog->log($error);
return false;
}
}
Then I use this code to unset the cookie:
private function destroyCookie($key){
if(setcookie(
$key,
" ",
time() - (time() + 2592000),
adminpath,
database::getDomain(),
database::getHTTPS(),
true
)){
return true;
}
else{
$error = array(
"type" => "other",
"argument" => 1,
"class" => __CLASS__,
"function" => __FUNCTION__,
"errorMsg" => "Could not destroy cookie ".$key,
"file" => __FILE__,
"line" => __LINE__
);
$this->errorlog->log($error);
return false;
}
}
I’m probably missing something very simple, but I can’t figure out why my cookie isn’t deleted.
Both functions are in the same class and the function database::getDomain() results in “www.creetab.com” and the function database::getHTTPS() results in “false”. adminpath is “/admin/”.
Could someone please help me fix this problem?
Setting the cookie works fine, it’s just deleting the cookie that doesn’t work.
should be:
Otherwise you are just giving it a value of an empty space, which is still a value. You want to give it no value at all, by making it empty. Also set the expiration time as above.