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.

Categories: web development php

Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 25 Days

Crash : 15 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 6 Months

Fastrack : 4 Months

Crash : 2 Months

Related Blogs

Request For Demo