How to close session in php

王林
Release: 2023-03-07 09:10:02
Original
2951 people have browsed it

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;];
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!