Correctly log out of PHP SESSION, log out of phpsession_PHP tutorial

WBOY
Release: 2016-07-13 09:57:20
Original
851 people have browsed it

Correctly log out of PHP SESSION, log out of phpsession

/*
1、每个页面都必须开启session_start()后才能在每个页面里面使用session。

2、session_start()初始化session,第一次访问会生成一个唯一会话ID保存在客户端(是基于cookie保存的),用户下次访问时,session_start()会检查有没有会话ID,如果有浏览器会带着这个会话ID过来(通过发送头文件传过来的,这个可以用ff浏览器看到)来确定客户端。

3、给于cookie的session会在客户端保存一个会话ID即session_id,这个可以通过打印cookie看到,这个session_id的键值为session_name,
session_id() == $_COOKIE[session_name()]

4、如果客户端禁用了cookie,则必须用url传递session_id即给予URL的SESSION

5、注销SESSION时不能用unset($_SESSION),可以使用$_SESSION = array()或则$_SESSION = null,正确注销session的方法如下:
*/

//正确的注销session方法:
//1开启session
session_start();

//2、清空session信息
$_SESSION = array();

//3、清楚客户端sessionid
if(isset($_COOKIE[session_name()]))
{
    setCookie(session_name(),'',time()-3600,'/');
}
//4、彻底销毁session
session_destroy();
Copy after login

 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/983247.htmlTechArticleCorrectly log out of PHP SESSION and log out of phpsession /*1. Each page must enable session_start() before it can be logged in Session is used in each page. 2. session_start() initializes the session, first...
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