2

How do I delete the session id while trying to destroy the session ?

session_start();
$_SESSION['foo'] = 'bar';

# clear the session variable
session_unset();
# delete the session
session_destroy();

# NOW WHAT ? HOW DO I UNSET THE SESSION-ID OR DELETE IT ?
2
  • why..? none of above works.?? Commented Mar 18, 2013 at 10:28
  • I think you need to do nothing... when you use session_destroy() everything related to it gets cleared .. Use print_r($_SESSION) to check it. Commented Mar 18, 2013 at 10:31

2 Answers 2

3

Not sure to understand the question, but dy deleting the cookie? (default name: PHPSESSID)

session_start();

session_destroy();

$args = array_merge(array(session_name(), ''), array_values(session_get_cookie_params()));
$args[2] = time() - 3600;
call_user_func_array('setcookie', $args);

session_destroy just delete the file (default handler) storing data, but if the cookie is not removed, the session id will be kept (and reused on the next call of session_start).

1
session_start(); // initialize the session variables

session_unset(); // clear the $_SESSION variable

if(isset($_COOKIE[session_name()])) {
    setcookie(session_name(),'',time()-3600); # Unset the session id
}

session_destroy(); // finally destroy the session

Not the answer you're looking for? Browse other questions tagged or ask your own question.