delete_cookies() helper not working in codeigniter 4

537 views Asked by At

I want to create a remember me feature on my website using cookie. when the user logout i want to destroy all session and cookies. But the problem is i can't delete existing cookie.

i'am using CodeIgniter 4 framework

i already loaded cookie helper in my BaseController. i tried this code in my logout controller :

delete_cookie('remember_me_token');

but that doesnt work, and also i tried this one :

set_cookie('remember_me_token', '', - 1209600); // set to minus

and the result is the same, i can't delete the cookie

please help :(

1

There are 1 answers

0
Dhaval Chheda On

I followed up with a different approach using the setCookie function which was chained using the response and simply set the expiry time to -1.

$this->response->setCookie(['name'   => 'token','value'  => "" ,'expire' => '-1','domain' => $domain, 'path'   => '/'])

Reference : https://codeigniter4.github.io/userguide/outgoing/response.html?highlight=set%20cookie