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