Địa Chỉ Product page which sets the session variable:
$_SESSION<"Products"><> = $_POST; //is how i mix the session on the add products page. unset $_SESSION<"Products"><>; //is how i have sầu tried khổng lồ clear the session although it does not work.Any point in the right direction will be appreciated!
You can unset session variable using:unset($_SESSION<"Products">); - Unset only Products index in session variable. (Remember: You have sầu lớn use lượt thích a function, not as you used)
To know the difference between using session_unmix & session_destroy, read this SO answer. That helps.
Bạn đang xem: Unset all session in php code example
Unmix is a function. Therefore you have sầu to submit which variable has khổng lồ be destroyed.
unset($var);In your case
unmix ($_SESSION<"products">);If you need lớn reset whole session variable just call
I am including this answer in case someone comes lớn this page for the same reason I did. I just wasted an embarrassing amount of time trying to lớn trachồng the problem down. I was calling:
unset($_SESSION<"myVar">);from a logout script. Then navigating to a page that required login, và the hệ thống still thought I was logged in. The problem was that the logout script was not calling:
session_start();Unsetting a session var DOES NOT WORK unless you start the session first.
If you completely want lớn clear the session you can use this:
session_unset();session_destroy();Actually both are not neccessary but it does not hurt.
If you want khổng lồ clear only a specific part I think you need this:
unset($_SESSION<"Products">);//or$_SESSION<"Products"> = "";depending on what you need.
unphối is a function, not an operator. Use it like unset($_SESSION<"key">); khổng lồ unmix that session key. You can, however, use session_destroy(); as well. (Make sure lớn start the session with session_start(); as well)
Destroying a PHPhường Session
A PHPhường. session can be destroyed by session_destroy() function. This function does not need any argument và a single Hotline can destroy all the session variables. If you want to destroy a single session variable then you can use unset() function to lớn unset a session variable.
Here is the example to unphối a single variable
Here is the call which will destroy all the session variables
Thanks for contributing an answer to Stachồng Overflow!
But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; baông xã them up with references or personal experience.
To learn more, see our tips on writing great answers.
Post Your Answer Disthẻ
Not the answer you're looking for? Browse other questions tagged php session or ask your own question.
After loging out from the welcome page & refreshing the homepage, it's redirect khổng lồ the welcome page
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP.
site thiết kế / biệu tượng công ty © 2021 Stachồng Exchange Inc; user contributions licensed under cc by-sa. rev2021.8.18.40012