Welcome Guest, Not a member yet? Register   Sign In
delete_cookie not working
#1

[eluser]Jaymey[/eluser]
Please help, I'm driven demented trying to get this to work.

Code:
if (get_cookie('usnapautologin'))
{
  echo "<h1>cookie exists</h1>";
  $cookie = array('name'   => 'usnapautologin');
  delete_cookie($cookie);    
  if (get_cookie('usnapautologin'))
  {
     echo "<h2>sh1t it's still there</h2>";
  }
  $this->autologin(get_cookie('usnapautologin', TRUE), '');
                
}
#2

[eluser]TheFuzzy0ne[/eluser]
Don't delete the cookie - eat it! Big Grin

...OK, now I've for that out of my system... Try this:
Code:
delete_cookie('usnapautologin');
#3

[eluser]Jaymey[/eluser]
Thanks, yea that's what I started with.

Put it in and tried again:
Code:
//not logged in. Check if there's a cookie set for auto login it
if (get_cookie('usnapautologin'))
{
  delete_cookie('usnapautologin');                
  if (get_cookie('usnapautologin'))
  {
    echo "<h2>shit it's still there</h2>";
  }
  $this->autologin(get_cookie('usnapautologin', TRUE), '');
    
}

Still not working Sad
#4

[eluser]TheFuzzy0ne[/eluser]
When are you calling delete_cookie()? Is it possible that the cookie headers have already been sent? Is the cookie still available on the request after if you don't call on the autologin method?
#5

[eluser]Jaymey[/eluser]
I have now put it in it's own method.

Still improvement. Could the cookie be defective?

Code:
function testcookie () {

    $this->load->helper('cookie');
    if (get_cookie('usnapautologin'))
    {
        delete_cookie('usnapautologin');                
        if (get_cookie('usnapautologin'))
        {
            echo "<h2>shit it's still there</h2>";
        }
        
        
    }
    else
        echo "no cookie";

}
#6

[eluser]TheFuzzy0ne[/eluser]
Unlikely, but you have nothing to lose by clearing that cookie yourself. Shoot the defector!
#7

[eluser]Jaymey[/eluser]
yea have done plenty of offender shooting, but he just keeps coming back and offending me...

Stumped on this now 8-<
#8

[eluser]TheFuzzy0ne[/eluser]
I'd recommend you install the [url="http://chrispederick.com/work/web-developer/"]Web Developer Extension[/url] for Firefox (if you haven't done so already). It allows you to view cookies, and see what's going on. I'm not sure if this will actually shed any light on the problem, I'm just getting desperate to solve this.
#9

[eluser]Jaymey[/eluser]
Quote:I’m just getting desperate to solve this.

LOL, me too...

I can't delete this damn cookie no matter what I do. It's not a code igniter problem cause I can't delete it with normal PHP either. I suspect it's something to do with how I'm setting the cookie.

I have modified the code so that it deletes the cookie right after it has created it, and it still won't delete...

Code:
$cookie = array(
'name'   => 'autologin',
           'value'  => $hash,
          'expire' => '86400',
           'domain' => 'mydomain.com.au' ,
           'path'   => '/',
           'prefix' => 'usnap_',
       );

set_cookie($cookie);
delete_cookie("usnap_autologin");
#10

[eluser]Samutz[/eluser]
I'm having this same problem.

Code:
function login ()
{
    // database stuff here blah blah blah
    set_cookie(array(
        'name' => 'user',
        'value' => $row->id, //from db
        'expire' => '86400' //24 hours
    ));
    set_cookie(array(
        'name' => 'hash',
        'value' => $this->_userhash($row->id), //function that makes a custom hash for this user
        'expire' => '86400'
    ));
    // checked firefox cookies at this point and there's no problem
}

function logout ()
{
    delete_cookie('user');
    delete_cookie('hash');
    // should delete cookies, but doesn't
    // firefox reports that they're still set with expiration in 24 hours
    print_r($_COOKIE); //also shows that they're still set
}

Edit: Got it to work using this:
Code:
set_cookie(array(
    'name' => 'user',
    'value' => null,
    'expire' => null
));
set_cookie(array(
    'name' => 'hash',
    'value' => null,
    'expire' => null
));




Theme © iAndrew 2016 - Forum software by © MyBB