Home  >  Article  >  Backend Development  >  Destruction of PHP session variables

Destruction of PHP session variables

韦小宝
韦小宝Original
2017-11-14 12:55:271630browse

1. What is session?

is equivalent to an access to the server by a client (which can be a browser, app, ftp, etc., and opening several more of the same browser can be considered different clients) , during this period the server creates a unique identifier (session_id session_name) for this purpose. session is actually an array Array(). The start and end of Session are not based on business input. It starts with the username and password and does not end with closing the browser and refreshing the webpagesession

2. Destruction of session variables

<?php
session_unset();
session_destroy();
?>
session_unset() //释放当前在内存中已经创建的所有$_SESSION变量,但不删除session文件以及不释放对应的session id
session_destroy() //删除当前用户对应的session文件以及释放session id,内存中的$_SESSION变量内容依然保留

[Note]:

Delete session method:

1. unset ($_SESSION['xxx']) Delete a single session, unset($_SESSION ['xxx']) is used to unregister a registered session variable. Its function is the same as session_unregister(). session_unregister() is no longer used in PHP5 and can be relegated to obsolescence.

unset($_SESSION) // 此函数千万不可使用,它会将全局变量$_SESSION销毁,而且还没有可行的办法将其恢复。用户也不再可以注册$_session变量。

2. $_SESSION=array() Delete multiple sessions

3. session_destroy() ends the current session and clears all resources in the session. . This function will not unset (release) global variables related to the current session, nor will it delete the client's session cookie. PHP's default session is based on cookies. If you want to delete cookies, you must use the setcookie() function.

 Return value: Boolean value.

Function description: This function ends the current session. This function has no parameters, and the return value is true

Session_unset() If $_session is used, then this function The function no longer works. Since PHP5 must use $_session, this function can be relegated to the sidelines.

It can be concluded that steps to delete session:

 ①session_start()

 ②$_SESSION=array()/unset ($_session['xxx'])

 ③session_destroy()

Related recommendations:

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

php uses session to prevent repeated page refreshes, phpsession prevents page_PHP tutorial

php passed Session anti-url attack method, phpsession anti-url_PHP tutorial

The above is the detailed content of Destruction of PHP session variables. For more information, please follow other related articles on the PHP Chinese website!

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