2
我有这个功能设置cookie:PHP不能删除的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;
}
}
然后我用这个代码来取消该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;
}
}
我可能失去了一些东西很简单,但我不明白为什么我的cookie不会被删除。 这两个函数都在同一个类中,并且函数database :: getDomain()的结果为“www.creetab.com”,函数database :: getHTTPS()的结果为“false”。 adminpath是“/ admin /”。 有人可以帮我解决这个问题吗? 设置cookie工作正常,它只是删除不起作用的cookie。
谢谢!这工作 – SheperdOfFire