• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
delete_cookie()

#1
[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");
}

#2
[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);

#3
[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.

#4
[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

#5
[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);

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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.