Home >Backend Development >PHP Problem >How to close session in php
How to close the session in php: You can use the unset() or session_destroy() function to close the session, such as [session_unset(); session_destroy();].
#If we want to delete some session data, we can use the unset() or session_destroy() function.
(Recommended tutorial: java video tutorial)
The following are three ways to destroy the session:
The code is as follows:
<?php /* session的销毁 */ @header('content-type:text/html;charset=utf-8'); session_start(); $_SESSION['username']='test1'; echo 'session没销毁时:'.$_SESSION['username']; echo "<br>"; //方法一 // $_SESSION['username']=null; //方法二 //session_unset(); //session_destroy(); //方法三 $_SESSION=array(); echo 'session销毁后:'.$_SESSION['username'];
Related recommendations: php training
The above is the detailed content of How to close session in php. For more information, please follow other related articles on the PHP Chinese website!