Home  >  Article  >  Backend Development  >  php session principle

php session principle

藏色散人
藏色散人Original
2019-11-01 09:36:222810browse

php session principle

php session principle

Session mechanism

session mechanism The solution is to maintain the state on the server side, and has its own corresponding unique identifier session_id to distinguish the previous information of different users.

How Session works

When a session is enabled for the first time, a unique identifier is stored in a local cookie;

First use the session_start() function, PHP loads the stored session variables from the session warehouse;

When the PHP script is executed, register it by using the session_register() function session variable.

When the PHP script execution ends, the session variables that have not been destroyed will be automatically saved in the local session library under a certain path. This path can be passed session.save_path# in the php.ini file. ##Specify that it can be loaded and used next time you browse the web.

Session’s advantages and disadvantages

Advantages

Uniqueness, convenient calling, and not occupying too many resources. It is a group of temporary files stored on the server. data. Under normal circumstances, when we log in as a user, we will store the user data in the session. In this way, it can be easily called on any page, and each client will generate a unique session_id without confusion. And after closing the browser, the server will have a session recycling mechanism to automatically delete expired sessions.

Disadvantages

The client is saved in the form of cookies. If cookies are disabled, the session will become invalid.

For more PHP related knowledge, please visit

PHP Chinese website!

Related topic recommendations: php session (including pictures, texts, videos, cases)

The above is the detailed content of php session principle. 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