How do I destroy a specific session variable in PHP?

you can use

  unset($_SESSION["products"]);

Use,

unset($_SESSION["products"]);

session_destroy() will destroy all the sessions, while the above line would destroy a specific session variable.


What about

unset($_SESSION["products"])

instead of the

session_destroy()

There is only one session per user. So there is no way to destroy a "specific" session. What you can do is delete the contents of your session responsible for the display of the cart (as shown above).

Tags:

Php

Session