Home  >  Article  >  Backend Development  >  How to destroy session variables in php

How to destroy session variables in php

怪我咯
怪我咯Original
2017-07-09 10:27:071150browse

This article mainly introduces the destruction of session variables in PHP. Friends in need can come and refer to it. I hope it will be helpful to everyone

1.What is session?
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 arrayArray(). 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. Ended by refreshing the server and web page

2. Destruction of session variables
Program code

<?php
session_unset();
session_destroy();
?>

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

session_destroy()
Delete the session corresponding to the current user file and release the session id, the contents of the $_SESSION variable in the memory are 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 (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.

We can get the steps to delete the session:

①session_start()

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

③session_destroy()

The above is the detailed content of How to destroy session variables in php. 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
Previous article:How to use php session?Next article:How to use php session?