ADD hàng hóa page which sets the session variable:
$_SESSION<"Products"><> = $_POST; //is how i set the session on the add products page. Unset $_SESSION<"Products"><>; //is how i have tried to 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 to use like a function, not as you used)
To know the difference between using session_unset và session_destroy, read this SO answer. That helps.
Bạn đang xem: Php sessions


Unset is a function. Therefore you have to lớn submit which variable has khổng lồ be destroyed.
unset($var);In your case
unset ($_SESSION<"products">);If you need to reset whole session variable just call
session_destroy ();

I am including this answer in case someone comes to this page for the same reason I did. I just wasted an embarrassing amount of time trying to track the problem down. I was calling:
unset($_SESSION<"myVar">);from a logout script. Then navigating to lớn a page that required login, và the server 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 to 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.
Xem thêm: Thai 40 Tuần Vẫn Chưa Chuyển Dạ Có Nguy Hiểm Không? Theo Dõi Thai 40 Tuần Chưa Có Dấu Hiệu Sinh
unset is a function, not an operator. Use it lượt thích unset($_SESSION<"key">); to unset that session key. You can, however, use session_destroy(); as well. (Make sure to lớn start the session with session_start(); as well)
Destroying a PHP Session
A PHP session can be destroyed by session_destroy() function. This function does not need any argument & a single điện thoại tư vấn can destroy all the session variables. If you want to destroy a single session variable then you can use unset() function to unset a session variable.
Here is the example khổng lồ unset a single variable
Here is the call which will destroy all the session variables
All the answer about unset are correct but one thing is needed khổng lồ be corrected. If you did not use session_start() the unset() will never work. I recommend doing it this way
session_start();unset($_SESSION<"productID">);
Thanks for contributing an answer to lớn Stack Overflow!
Please be sure khổng lồ answer the question. Provide details and share your research!But avoid …
Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.
Post Your Answer Discard
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy và cookie policy
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 to lớn the welcome page
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
Site design / logo © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. Rev2022.6.15.42378
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device và disclose information in accordance with our Cookie Policy.