Application of the PHP user status management function. User status management (sessionsupport) is a new feature that has long been expected in PHP4.0. In the PHP3.0 era, session support is a new feature in PHP 4.0 that requires programmers to use a library written by others to implement user status management. In the PHP 3.0 era, programmers must use the function library written by others to implement the state management function, or simply give up this function. The lack of status management is actually one of the most disappointing parts of PHP 3.0. However, the status has changed. since the early beta version of PHP 4.0, user status management has become one of the built-in functions of PHP.
You can use the status management function to manage all the variables related to a user's website from the beginning to the end of the website. (these variables can be used as long as the user has not left the website, does not cause data to disappear because the user leaves a single page), instead of storing many cookies, hiding form fields, or even storing these variables in the database, this causes a large load on the database server.
Once you activate status management on a page of your website, the PHP engine starts to record the user status (if the system hasn't started recording the visitor status for this user ), or you can continue recording the status of a previously activated user. To activate the PHP state management function, you can use the following syntax:
Session_start ();
Once the status management is activated, PHP sends a unique status code (the code looks like 940f8b05a40d4249c030c9c7745aead9) to the user through the cookie, and at the server end, the PHP engine automatically generates a temporary text file (for example, sess_940f8b05a40d4249c030c9c7745aead9) corresponding to the file name and status code ), this file is used to store all variables registered by the programmer in this user status record.
When talking about user status management, the most commonly used example is an access counter: now I am going to teach you how to write PHP code.
Special note
Before you try to activate the user status record, you cannot output any content (there cannot be spaces, tabs, line breaks, and other space characters, nor any HTML volume labels, nor any content) to the browser. This is because the status management function sends the HTTP header information to the browser. if other content has been output before sending the HTTP header information to the browser, the system displays an error message.
If the user's status management has not been activated, the following program will activate the user's status management:
Session_start ();
Next, register a variable named count:
Session_register ('count ');
Once you register a variable, PHP automatically maintains the variable value for you throughout the browsing process from the user's website to the website's departure, you can use these registered variables at any time. The newly registered variable does not specify any value for it, but once we increase the value of the count variable, its value will be 1:
Session support is a new feature that has long been expected in PHP 4.0. In the era of PHP 3.0, programmers must use the library written by others to implement the code...