Home > Article > Backend Development > How to set up session in php
Open the editor and comment
First open the php editor sublime, and then create a new file for the upcoming The program should be written with comments.
Create a new function
We put the setting and use of session in the function for easy management. Here we create a new one Function use_session.
Related recommendations: "PHP Tutorial"
Start session
If you want To use session, we must first start the session. To start the session, we use session_start.
Set session
We set session through $_SESSION, the format is as follows:
$_SESSION[ 'session name']=value;
Get the value of the session
It is also very simple to get the value of the session , or implemented through $_SESSION, the format is as follows:
$_SESSION['session name'].
Destroy session
If we feel that the set session is no longer needed, we can destroy the session and use unset This function is used to destroy the session.
session_destroy
In addition to using the unset function to destroy a session in php, you can also use session_destroy to destroy it.
The above is the detailed content of How to set up session in php. For more information, please follow other related articles on the PHP Chinese website!