You can unset session variable using:

  1. session_unset - Frees all session variables (It is equal to using: $_SESSION = array(); for older deprecated code)
  2. unset($_SESSION['Products']); - Unset only Products index in session variable. (Remember: You have to use like a function, not as you used)
  3. session_destroy โ€” Destroys all data registered to a session

To know the difference between using session_unset and session_destroy, read this SO answer. That helps.

Answer from Thamilhan on Stack Overflow
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.session-unset.php
PHP: session_unset - Manual
If $_SESSION is used, use unset() to unregister a session variable, i.e.
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_sessions.asp
PHP Sessions
session_unset() - Frees all session variables ยท A session is started with the session_start() function. Note: The session_start() function must be callled at the beginning of every PHP script, before any HTML output or whitespace!
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ home โ€บ php โ€บ php sessions management
PHP Sessions Management
May 26, 2007 - This function does not need any argument and a single call 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.
๐ŸŒ
sebhastian
sebhastian.com โ€บ php-unset-session-variable
PHP how to unset a session variable | sebhastian
September 28, 2022 - The unset construct allows you ... "en"; $_SESSION["theme"] = "dark"; // ๐Ÿ‘‡ unset two session variables unset($_SESSION["User"], $_SESSION["lang"]); // ๐Ÿ‘‡ Array ( [theme] => dark ) print_r($_SESSION); ?>...
๐ŸŒ
SitePoint
sitepoint.com โ€บ php
Unset() and session_destroy(); - PHP - SitePoint Forums | Web Development & Design Community
December 2, 2009 - <?php session_start(); if(isset($_SESSION["user_name"])) if($_GET["destroy"]=="yes") { unset($_SESSION["user_name"]); session_destroy(); } if(!isset($_SESSION["user_name"]) && $_GET["user"]!="") $_SESSION["user_name"] โ€ฆ
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ php-unset-session-variable
PHP | Unset Session Variable - GeeksforGeeks
July 20, 2020 - Example: The following PHP function unregisters or clears a session variable whenever $_SESSION is used in some code. It is mostly used for destroying a single session variable. ... <!DOCTYPE html> <html> <head> <style> body { width: 450px; height: 300px; margin: 10px; float: left; } .height { height: 10px; } </style> </head> <body> <h1 style="color:green">GeeksforGeeks</h1> <b> PHP Unset session variables </b> <div class="height"> </div> <?php // start a new session session_start(); // Check if the session name exists if( isset($_SESSION['name']) ) { echo 'Session name is set.'.'<br>'; } else { echo 'Please set the session name !'.'<br>'; } echo'<br>'; $_SESSION['name'] = 'John'; //unset($_SESSION['name']); echo "Session Name : ".$_SESSION['name'].'<br>'; ?> </body> </html>
Find elsewhere
๐ŸŒ
W3Resource
w3resource.com โ€บ php-exercises โ€บ cookies-sessions โ€บ php-cookies-sessions-exercise-6.php
Destroy PHP session and unset all session variables
<?php session_save_path('i:/custom/'); session_start(); // Unset all session variables $_SESSION = []; // Destroy the session session_destroy(); echo "Session destroyed. All session variables have been unset."; ?> ... Session destroyed.
๐ŸŒ
EITCA
eitca.org โ€บ home โ€บ how can we delete a session variable in php?
How can we delete a session variable in PHP? - EITCA Academy
August 8, 2023 - To delete a session variable in PHP, you can use the unset() function or the session_unset() function. Both methods allow you to remove a specific session variable, clearing its value from the current session. The unset() function is a built-in PHP function that destroys a given variable.
๐ŸŒ
Hoststud
hoststud.com โ€บ home โ€บ resources โ€บ languages โ€บ php
How to Unset Session Variable in PHP? | Web Hosting Forum - Review - Community & Resources
October 13, 2020 - session_unset(); Therefore the PHP Unset session variable is use to clear the session that was created by the PHP engine. ... A brief overview of Docker. A brief overview of Docker.
๐ŸŒ
Jobtensor
jobtensor.com โ€บ Tutorial โ€บ PHP โ€บ en โ€บ Sessions
PHP Sessions - session_start(), $_SESSION, session_unset(), session_destroy() | jobtensor
<?php session_start(); // starts the session // Storing session data $_SESSION["user"] = "admin"; $_SESSION["password"] = "password"; echo 'Username: ' . $_SESSION["user"]; echo '<br>'; echo 'Password: ' . $_SESSION["password"]; session_unset(); // removes session variables session_destroy(); // destroys the session // try to access the session variables after session is destroyed echo '<br>' .
๐ŸŒ
PHPpot
phppot.com โ€บ php โ€บ php-session-destroy
PHP Session Destroy after 30 Minutes - PHPpot
For an older PHP version, use session_unset(). Letโ€™s create a login example code to use PHP session, session_destroy and all. It allows users to login and logout from the current session. Use this code if you are looking for a complete user registration and login in PHP script.
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ php tutorial โ€บ sessions in php
Sessions in PHP | Learn How to Create And Delete Sessions in PHP?
March 16, 2023 - ... <?php //example to unset session variables //starting a session session_start(); print_r($_SESSION); //before destroying the session //printing the session unset($_SESSION['name']); unset($_SESSION['age']); echo 'Session destroyed'; //after ...
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Hostnet
phpweb.hostnet.com.br โ€บ manual โ€บ en โ€บ function.session-destroy.php
PHP: session_destroy - Manual
All $_SESSION variable can be viewed (and CHANGED , which is how this kludge works) but for some reason (that no doubt someone will illuminate) they can't be unset...setting the particular variable to NULL works well though: $_GET[session_name()]=$sid; session_start(); // prove we are getting ...