Home > Article > Backend Development > How to use php session
To use session in php, you must first start the session. To start the session, use the php built-in function session_start(), as shown in the figure. (Recommended learning: PHP video tutorial)
Then the session_start() function must be located before the tag before it can be used, such as As shown in the figure.
After starting the session, use PHP’s built-in array object $_SESSION[] to store it and create a new index.php file.
In the index.php file, write the following code to store the content in the session.
After saving, just take out the key value you just saved, use the [echo $_SESSION['views']] command.
Enter localhost:8080/jingyan/ssy/index.php in the browser, you can see the value stored in the $_SESSION variable.
Related topic recommendations: php session (including pictures, texts, videos, cases)
The above is the detailed content of How to use php session. For more information, please follow other related articles on the PHP Chinese website!