Home  >  Article  >  Backend Development  >  How to use php session

How to use php session

(*-*)浩
(*-*)浩Original
2019-10-11 10:15:263595browse

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)

How to use php session

Then the session_start() function must be located before the tag before it can be used, such as As shown in the figure.

How to use php session

After starting the session, use PHP’s built-in array object $_SESSION[] to store it and create a new index.php file.

How to use php session

In the index.php file, write the following code to store the content in the session.

How to use php session

After saving, just take out the key value you just saved, use the [echo $_SESSION['views']] command.

How to use php session

Enter localhost:8080/jingyan/ssy/index.php in the browser, you can see the value stored in the $_SESSION variable.

How to use php session

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!

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