


Solve the problem of losing session value when passing PHP session across pages (picture and text)
Solve the problem of session value loss when passing PHP session across pages. If you have encountered this problem, please refer to it. The operating mechanism of session:
Solve the problem of session value loss when passing PHP session across pages. For friends who have encountered this problem, please refer to it. Session operating mechanism: Session is a session mechanism on the server side. When the client requests the server to create a session, the server will first detect whether the request contains a unique session ID. If so, it means that the server has already created a session for the user. As long as the session ID is created, the server will Retrieve the user's session for the user to use. If there is no session ID, the server will create a new session with a unique session ID for the user. After the creation is completed, the session ID will be returned to the client by the server and saved locally on the client. The general mechanism for saving the session ID is Cookie, but since Cookies can be artificially disabled, it is necessary to ensure that after Cookies are disabled, the session can still be conducted through the session, usually through url rewriting, in the form of http:// ...../xxx;jsessionid= ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng!-145788764, the other is as a query string attached to the back of the URL, in the form of http://...../xxx?jsessionid=ByOK3vjFD75aPnrF7C2HmdnV6Q ZcEbzWoWiBYEnLerjQ99zWpBng!-145788764this There is no difference between the two methods for users, but the way the server handles them during parsing is different. Using the first method is also helpful to distinguish session id information from normal program parameters. In order to maintain state throughout the entire interaction, this session id must be included at the end of every path that the client may request. Solution to lost session: 1. session_start(); should be placed at the top of the page as much as possible; 2. If session Autostart is not configured in php.ini, you must manually open the session before each session: session_start(); 3. Session is a super global variable in PHP, the same as $_GET, $_POST, $_SERVER, so it must be capitalized when used: $_SESSION['username']=$username; 4. Cross-page transfer example: a.php page transfers $_SESSION['username'] to b.php: a.php: ![]() Attachment: Misunderstandings about session invalidation: When talking about the session mechanism, we often hear the misunderstanding that "as long as you close the browser, the session will disappear." In fact, you can imagine the example of a membership card. Unless the customer actively asks the store to cancel the card, the store will never delete the customer's information easily. The same is true for sessions. Unless the program notifies the server to delete a session, the server will keep it. The program usually sends an instruction to delete the session when the user logs off. However, the browser never actively notifies the server that it is about to close before closing, so the server has no chance to know that the browser has been closed. The reason for this illusion is that most session mechanisms use session cookies to save session ids. , and the session id disappears after closing the browser, and the original session cannot be found when connecting to the server again. If the cookie set by the server is saved to the hard disk, or some method is used to rewrite the HTTP request header sent by the browser and send the original session ID to the server, the original session can still be found when the browser is opened again. It is precisely because closing the browser will not cause the session to be deleted, forcing the server to set an expiration time for the seesion. When the time since the client last used the session exceeds this expiration time, the server can consider that the client has stopped activities. , the session will be deleted to save storage space. |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
