简体   繁体   中英

CakePHP: using Cookie component during logout

I'm trying to delete/unset additional cookies during the logout action in my cakePHP app. I'm trying all three methods and none of them seem to have any effect whatsoever. Here's what is in UsersController.php:

public function logout() {

    $wp_cookie = grab_wp_cookie(); //this grabs the extra cookie name/value 
    $cookie_name = (isset($wp_cookie['name'])) ? $wp_cookie['name'] : NULL;
            //none of these do anything...
    $this->Cookie->write($cookie_name, 'xxx', false, strtotime('-1 day'));
    $this->Cookie->delete($cookie_name);
    $this->Cookie->destroy();

    $this->redirect($this->Auth->logout());
}

Am I missing something? I found this documentation but it doesn't indicate anything problematic about what I'm doing. However it does show a lot of configuration optoins in the beforeFilter() which I have not used.

I hope someone can provide a better answer which explains why the cake methods aren't working, but in the mean time, I was actually able to get this to work using the PHP setcookie() which wasn't working previously.

I was doing this with no success:

    setcookie($cookie_name, "XXX", time()-3600);

But THIS works:

    setcookie($cookie_name, "XXX", time()-3600, '/');

Apparently the fourth parameter was necessary. I'm surprised this issue isn't talked about more in the documented or other threads that I found on this subject.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM