Home > Backend Development > PHP Tutorial > Logout and clearing of SESSION in PHP, phpsession logout_PHP tutorial

Logout and clearing of SESSION in PHP, phpsession logout_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:56:50
Original
1001 people have browsed it

Logout and clearing of SESSION in PHP, phpsession logout

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:

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

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/985278.htmlTechArticleLogout and clearing of SESSION in PHP, phpsession logout 1. Each page must turn on session_start() before it can be logged out Session is used in each page. 2. session_start() initializes the session,...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template