Home > Backend Development > PHP Tutorial > Destruction of session variables in PHP_PHP tutorial

Destruction of session variables in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:36:50
Original
1011 people have browsed it

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 clients on the same browser can be considered different clients). During this period The server creates a unique identifier (session_id session_name) for this purpose, which is actually an array Array(). The beginning and end of the Session does not start with entering the username and password in the business, nor does it end with closing the browser and refreshing the web page.

2. Destruction of session variables
Program code
session_unset();
session_destroy();
?>

session_unset()
Release all $_SESSION variables currently created in the memory, but do not delete the session file and do not release the corresponding session id

session_destroy()
Deletes the session file corresponding to the current user and releases the session id. The content of the $_SESSION variable in the memory is still retained

【Note】:

Delete session method:

1. unset ($_SESSION['xxx']) deletes a single session, and 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) This function must not be used, it will destroy the global variable $_SESSION, and there is no feasible way to restore it. Users can also no longer register the $_session variable.

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() This function no longer works if $_session is used. Since PHP5 must use $_session, this function can be relegated to the sidelines.

The steps to delete the session can be drawn:

①session_start()

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

③session_destroy()

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736845.htmlTechArticle1. What is session? It is equivalent to an access to the server by a client (it can be a browser, app, ftp, etc., and if you open several more clients on the same browser, they are considered different clients),...
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