The http protocol is stateless. for each request, the server cannot distinguish users. Php session control is to give users a key (an encrypted session string), and this is also a proof of user identity. the server stores the box (database, memory database or files), the box contains the user's variable information.
Overview
The http protocol is stateless. for each request, the server cannot distinguish users. Php session control is to give users a key (an encrypted session string), and this is also a proof of user identity. the server stores the box (database, memory database or files), the box contains the user's variable information.
Where is the key?
1. url query string
2. in the browser cookie
Traditional php session usage
Ask a question. what about the key? Didn't you see the operation for the user key?
This operation is behind php. since you visit page1.php to run the program session_start (), php will follow the conditions (user ip address, browser number, generate a PHPSESSID variable. after http response returns to the client, the PHPSESSID will already exist in your browser cookie. every time you access this domain name again, the PHPSESSID will be sent to the server. This PHPSESSID is the user key I mentioned here.
Another question is: is PHPSESSID security easy to steal, forge, or tamper?
Https can be used to prevent tampering. Instead of using PHPSESSID, you can generate a secret key to prevent forgery. I have never studied whether it is easy to be stolen. For example, if your computer is connected to the Internet, hackers intrude into your computer.
Store the generated key in the browser cookie.Set cookiesetCookie ('key', 'value', time () + 3600); delete cookiesetCookie ('key', '', time ()-1 );Single Sign-On: session sharingSingle Sign-On: multiple subsystems share a set of user verification systems. you can access all subsystems by logging on to one of them.
Suppose that the php environment of server A and server B is the same. The user obtained his key on server A, and then he took the key to access server B. do you know server B?
Obviously, the key generated by server A is not recognized by the server.
Solution: no matter the user accesses A or B, the generated keys are stored in C (the same database or cache system). when the user accesses A or B again, both A and B ask C: is this user's key correct? If yes, you can use the boxes that exist in A or B.
$ Uid, 'session' => session_encrypt (session_id (). time (); // Save $ session_info to C.
The above is a detailed description of the php session control instance code. For more information, see other related articles in the first PHP community!