Home > Backend Development > PHP Tutorial > Logout and Clearance of SESSION in PHP_PHP Tutorial

Logout and Clearance of SESSION in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 09:57:05
Original
865 people have browsed it

Logout and clearing of SESSION in PHP

1. Session_start() must be enabled on each page before session can be used in each page.

2. session_start() initializes the session. The first visit will generate a unique session ID and save it on the client (saved based on cookies). The next time the user visits, session_start() will check whether there is a session ID. If Some browsers will bring this session ID (passed by sending a header file, which can be seen with ff browser) to determine the client.

3. The session given to the cookie will save a session ID, session_id, on the client. This can be seen by printing the cookie. The key value of this session_id is session_name,
session_id() == $_COOKIE[session_name()]

4. If the client disables cookies, the session_id must be passed in the URL, which is the SESSION given to the URL

5. You cannot use unset($_SESSION) when logging out of a SESSION. You can use $_SESSION = array() or $_SESSION = null. The correct way to log out a session is as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

//正确的注销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();

1 2 3

4

6 7 8 9 10
11 12
13 14
//Correct method to log out session: //1Open session session_start(); //2. Clear session information $_SESSION = array(); //3. Clear client sessionid if(isset($_COOKIE[session_name()])) { setCookie(session_name(),'',time()-3600,'/'); } //4. Completely destroy the session session_destroy();
http://www.bkjia.com/PHPjc/985141.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/985141.htmlTechArticleLogout and clearing of SESSION in PHP 1. Session_start() must be turned on on each page before you can log out on each page Session is used inside. 2. session_start() initializes the session. The first visit will occur...
Related labels:
php
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