-2
我正在CakePHP中構建API。我有一個函數,作爲其執行的一部分,首先破壞與會話相關的cookie。我正在使用下面的代碼來做到這一點。不能從CakePHP 2.x中的控制器中過期cookie
public function new_thing() {
// I first call another controller to use functions from that controller
App::import('Controller', 'Person');
$PersonsController = new PersonsController;
// This function call is the problem
// This does not throw any errors but does not destroy the cookie as requested
$PersonsController->_kill_auth_cookie()
}
// This is from the Person controller, these are the functions used in the API
// This is the function that sets the cookies
public function _set_auth_cookie($email) {
setcookie(Configure::read('auth_cookie_name'), $email);
}
// this is the function that does not properly destroy the cookie from the API
// interestingly, it does work when called from in this controller
public function _kill_auth_cookie() {
setcookie(Configure::read('auth_cookie_name'), 'xxx', time()-7200);
}
我無法讓API正確過期在會話中創建的cookie,我不知道爲什麼。此外,令人生氣的是,日誌是空的,沒有任何錯誤發生,所以我不知道下一步該怎麼做。
好主,這是一些可怕的代碼。 @burzum在總結原因方面做得很好。 –