Home > php教程 > PHP开发 > body text

Destruction of session variables in PHP

高洛峰
Release: 2016-12-24 09:14:09
Original
1206 people have browsed it

1.What is session?
Equivalent to a client (can be a browser, app, ftp, etc., and if you open several more clients in the same browser, they are considered different clients), during this period the server establishes a unique identifier for this purpose (session_id session_name), in fact, it is an array Array(). The beginning and end of the Session does not start with entering the user name 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 memory, but do not delete the session file and do not release the corresponding The 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, 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() deletes 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, this function will no longer work. Since PHP5 must use $_session, this function can be relegated to the sidelines.

The steps to delete session can be drawn:

①session_start()

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

③session_destroy()


More sessions in PHP For articles related to the destruction of variables, please pay attention to the PHP Chinese website!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template