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
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 09:56:501024browse

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

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,...
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