Welcome Guest, Not a member yet? Register   Sign In
Problem Deleting Cookie
#1

[eluser]Joey Marchy[/eluser]
Not sure what I am missing with the delete_cookie function. I've tried it a few different ways, Nothing I have done will clear the cookie value/ Here is the code snippet:

Code:
$this->load->helper('cookie');
$cookie = array(
'name'   => 'ee_ci_id',
'value'  => 'active',
'expire' => '173000',
'domain' => '.apol0829.dev',
'prefix' => 'apollidon_');
set_cookie($cookie);
echo 'cookie ' . get_cookie('apollidon_ee_ci_id');

Outputs: cookie active

I tried this:
delete_cookie('ee_ci_id');

This:
$cookie_delete = array(
'name' => 'ee_ci_id',
'domain' => '.apol0829.dev',
'prefix' => 'apollidon_');

This:
set_cookie('ee_ci_id', '', '', '.apol0829.dev', '', 'apollidon_');

This:
set_cookie('ee_ci_id', '', '0', '.apol0829.dev', '', 'apollidon_');

This:
set_cookie('ee_ci_id', '', '-1', '.apol0829.dev', '', 'apollidon_');

Thanks!
#2

[eluser]thinkigniter[/eluser]
Direct from php site

Quote:Here is problem I ran into during a recent bout with IE7 and cookies. IE will not delete a cookie value if the time is set to the past. It will hold the value no matter how far in the past you set the "expire" value. IE7 is the only browser I have had problems with - so here is the solution I came up with.
Code:
<?PHP

//check to see how to set the cookie
$Browsertype = $_SERVER['HTTP_USER_AGENT'];
$Parts = explode(" ",$Browsertype);
$MSIE = array_search("MSIE",$Parts);
                
if($MSIE)
{
setcookie("name", "", time()+20000);
}
else
{
setcookie("name", "", time()-20000, "/", ".domain.com" );
}

?>

Give it a try
#3

[eluser]Joey Marchy[/eluser]
It's not specifically an IE issue. At this point the delete_cookie function is not working across the browsers. The cookie helper documentation in the user guide states:

Quote:The expiration is set in seconds, which will be added to the current time. Do not include the time, but rather only the number of seconds from now that you wish the cookie to be valid.

So my question is related directly to the cookie helper. At this point is seems to not be working as advertised, or at least the delete_cookie portion of the helper.

If anyone else has other ideas or thoughts it would be greatly appreciated.
#4

[eluser]Joey Marchy[/eluser]
After some more testing and finding this post in the forums removing the underscores from my cookie name fixed the problem I was having with the cookie helper not working.

http://ellislab.com/forums/viewthread/90364/P15/#459871

So to recap:

Code:
$cookie = array(
'name'   => 'loggedin',      //NOT logged_in
'value'  => 'yes',
'expire' => '86500',
'domain' => '.domain.com',
'prefix' => 'areyou_'
);

set_cookie($cookie);

echo 'logged in ' . get_cookie('areyou_loggedin');           //prints: logged in yes
echo 'logged in ' . delete_cookie('areyou_loggedin');     //prints: nothing, cookie was deleted




Theme © iAndrew 2016 - Forum software by © MyBB