CakePHP Delete Cookie

I have looked at other people's problems similar to this, but nothing is like what I am experiencing. Please feel free to link to my article if this has been reviewed previously.

I wrote a cookie when the user authenticates, and locally stores some basic user information. When the user logs out, I try to delete the cookie variable, but it is not deleted. If I use the destroy method, the cookie is deleted, but I'm curious what I'm doing wrong here:

Cookie is written this way and it works:

function login(){ if($this->Auth->login($this->data)){ $this->Cookie->write('User.email',$this->data['User']['email'],true, '1 day'); } } 

However, using the delete function does not work ...

 function logout(){ $this->Cookie->delete('User'); if($this->Auth->logout($this->data)){ //auto redirected } } 

If I replaced delete with destroy, it will work. This does not work because the cookie data is encrypted? I'm probably doing something stupid, but I can't figure out how to figure it out.

I use this cookie to continue my sessions. I want it to be deleted if the user clicks the logout button.

Thanks!

+4
source share
1 answer

Looking through the source, it looks like this is either an error or an alleged behavior.

The CookieComponent class has an internal __values ​​array that it uses to track cookie information. If you select delete ("User.email"), it will remove the User index from the __values ​​array, including all data under the index.

However, it will only cancel the cookie named "User". The next time Cake appears, it sees that a cookie with the name "User.email" still exists and loads it back into the __values ​​array.

Assuming this is not intended behavior, I wrote a fix and I will send it to the Cake command.

+4
source

Source: https://habr.com/ru/post/1347984/


All Articles