Difference between session_destory() and session_unset() in PHP

Difference between session_destory() and session_unset() in PHP

In this blog, you will learn the difference between session destroy and session unset.  The session is used to make data accessible across the various pages of the website. It is mostly used in the login and logout forms.

Sometimes web developers want to destroy a particular session of the website and sometimes they want to destroy all sessions of the website but they got confused between the session_destory() and session_unset() method. So this blog has a solution for you:


session_destroy() function in PHP

session_destroy() function is used to destroy all the sessions of the website.

Syntax:


<?php
session_destroy();
?>
 


session_unset() function in PHP

session_unset() function is used to destroy specific sessions of the website, it does not destroy all the sessions like session_destory().

Syntax:

<?php
session_unset($_SESSION[‘username’]);
?>


It will only destroy the username session of the website.