我有这个功能来设置一个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”。管理路径是“/admin/”。有人可以帮我解决这个问题吗?设置 cookie 工作正常,它只是删除不起作用的 cookie。