session overview

What we want to learn in this part is session technology.
Through the study in the previous section, we know that Cookie maintains the connection with the server by saving data on the client, and Session maintains the connection with the server through Save the data on the server side to maintain the connection. Let's understand the mechanism of session through an example.

We go to the beverage shop to buy drinks. After placing the order, the waiter will give us a number tag. Then you walk aside. The waiter does not know who you are. If you want to get your drink, you must provide it. You can only give your number plate to the waiter. The waiter will check the record through the number plate to confirm that you are a customer and confirm what drink you ordered, and then give you the drink you ordered.

After understanding the session principle, and returning to Web technology, we have two methods for the client to get the "number plate", one is through cookies, and the other is by embedding the value in the web page and passing it to the client. end. We also have two methods for the client to pass the number plate to the server to get its own data, one is cookie, and the other is standard Query String/POST.

What we commonly use is cookies, because all modern browsers support cookies and are turned on by default. Both the client and the server will send cookies to each other. Let’s explain the process: Open the browser and enterwww.taobao.comand press Enter. Since this is the first time to establish a connection with this website, the server has not set a cookie (here it is assumed that the current browser is The first time you visit this URL, this URL has not written a cookie to the current client before), so no cookie is sent to the server. When the server returns after processing the data, it will have a name of sessionid and a value of a series of N digits. The character cookie is sent to the client. When the client visits the server again, it will also bring this cookie to visit the server. So, they "get to know" each other through sessionid.

Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!