0

I'm trying to make a simple logout script for my site, but for some reason, I can't kill this cookie. I was able to kill another cookie which I named "fontCookie" but this default-named one won't go away. What could be causing this issue? This is what I have, and I repeat, fontCookie is being destroyed:

<?php  
session_start();  

if(isset($_SESSION["loggedin"])){

$_SESSION = array();


    if(isset($_COOKIE['fontCookie'])){

    setcookie('fontCookie', '', time() -42000);

    }
    if ( isset( $_COOKIE[session_name()] ) ){

    setcookie( session_name(), '', time()-42000);

    }

    session_destroy();

    header('Location: http://google.com');
}
else{

    header('Location: http://google.com');
}


?> 
Sam
  • 2,309
  • 9
  • 38
  • 53
  • You shouldn't need to remove the cookie... – John V. May 11 '13 at 02:37
  • @JohnVanDeWeghe, but why can't I remove it with code? It only gets deleted if I use the GUI in my browser – Sam May 11 '13 at 02:48
  • When the cookies are marked as expired it's possible they aren't actually removed until the browser restarts. Did you check multiple browsers to see if that was the case? – John V. May 11 '13 at 02:51
  • 1
    Oh, read this: http://stackoverflow.com/questions/3989347/php-why-cant-i-get-rid-of-this-session-id-cookie – John V. May 11 '13 at 02:53

2 Answers2

0

It seems you need to call session_name() before session_start()

The session name is reset to the default value stored in session.name at request startup time. Thus, you need to call session_name() for every request (and before session_start() or session_register() are called). refer here

Amir
  • 4,089
  • 4
  • 16
  • 28
0

Try deleting cookie like this.

 setcookie('fontCookie', '', time() -42000);
 $_COOKIE["fontCookie"] = null;
 unset($_COOKIE["fontCookie"] );
soachishti
  • 341
  • 2
  • 13