CodeIgniter Forums
delete_cookie() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: delete_cookie() (/showthread.php?tid=52810)



delete_cookie() - El Forum - 06-27-2012

[eluser]ci_user[/eluser]
I'm trying to delete cookies on logout without success... any suggestions? My code is:
Code:
function logout(){
  $this->load->helper('cookie');
  delete_cookie('csrf_cookie_security');
  delete_cookie('anothercookie');
  $this->session->sess_destroy();
  $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
  $this->output->set_header("Pragma: no-cache");
}



delete_cookie() - El Forum - 06-27-2012

[eluser]InsiteFX[/eluser]
To delete a cookie the time has to be in the pass the cookie helper does not set an expire time.

You can use this which should work
Code:
// set the expiration date to - the cookie time
setcookie('csrf_cookie_security', '', time()-31500000);



delete_cookie() - El Forum - 06-27-2012

[eluser]ci_user[/eluser]
I tried both without success. I thought set_cookie creates a cookie, not updates an existing cookie?
Code:
setcookie('csrf_cookie_security', '', time()-31500000);


Also tried this which I believe is the CI way to set a cookie.
Code:
set_cookie('csrf_cookie_security', '', time()-31500000);

Neither one deleted the cookie... It is frustrating that delete_cookie() won't work if there is no expiration set.



delete_cookie() - El Forum - 06-27-2012

[eluser]InsiteFX[/eluser]
Setcookie is used for all of the cookies methods the difference is in the time see the -31500000

A cookie is deleted when the time has expired so by setting the time()-31500000 sets the cookie to expired.
Which deletes it.

W3Schools
setcookie

PHP net
setcookie



delete_cookie() - El Forum - 12-20-2012

[eluser]Kraig[/eluser]
[quote author="InsiteFX" date="1340816949"]Setcookie is used for all of the cookies methods the difference is in the time see the -31500000

A cookie is deleted when the time has expired so by setting the time()-31500000 sets the cookie to expired.
Which deletes it.

W3Schools
setcookie

PHP net
setcookie
[/quote]

I have tried what you said and when I try to logout the cookie's life doesn't get adjusted. Any ideas?

Code:
// set the expiration date to - the cookie time
$this->input->set_cookie('rmt', '', time()-315000000);



delete_cookie() - El Forum - 12-20-2012

[eluser]Kraig[/eluser]
Answered my own question....all I had to do was set $config['cookie_domain'] = ".www.yoursite.com";


delete_cookie() - El Forum - 12-20-2012

[eluser]InsiteFX[/eluser]
lol i was just going to ask you if you had set it...