Home  >  Article  >  Backend Development  >  How to close session in php

How to close session in php

王林
王林Original
2020-11-04 13:59:112996browse

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();].

How to close session in php

#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(&#39;content-type:text/html;charset=utf-8&#39;);
session_start();
$_SESSION[&#39;username&#39;]=&#39;test1&#39;;
echo &#39;session没销毁时:&#39;.$_SESSION[&#39;username&#39;];
echo "<br>";
//方法一  
// $_SESSION[&#39;username&#39;]=null;  
//方法二  
//session_unset();  
//session_destroy();  
//方法三  
$_SESSION=array();
echo &#39;session销毁后:&#39;.$_SESSION[&#39;username&#39;];

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn