How to delete PHPSESSID

Asked

Viewed 533 times

0

I’m making a cart with $_SESSION and when the purchase is completed, should clean or delete the PHPSESSID (self-created). But I’m not able to delete or update. I’ve tried with unset() and session_destroy() and even trying to delete as cookie, but I’m not getting anything.

  • has tried to expire before the unset();

  • 1

    Enter the code to see how you are performing

2 answers

2

1


The function session_destroy will not delete the PHPSESSID, will only remove all the contents of the variable $_SESSION. This function does not remove the session cookie.

Just remembering that session_destroy does not remove data from $_SESSION at the time it was executed, but yes at the next request.

If you want to clear all variable data $_SESSION, just use session_reset. This function will erase all data from the above variable at the time it is executed.

Particularly I see no reason to delete the value of PHPSESSID since you can use the above functions or still unset.

But if you really want to remove this cookie, just use the function setcookie.

setcookie(session_name(), null, 0);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.