Home > Article > Backend Development > Conversation on the couch (1)_PHP tutorial
开始治疗
心理医生: 好。你今天感觉怎么样,维克多?西雅图无状态
One of the most common things people who make crude jokes say to each other in order to impress young women who can hear the conversation is: "HTTP is a stateless protocol, and the Internet is a stateless development environment." In simple terms, the HTTP (HyperText Transfer Protocol) protocol, as the backbone of the web, cannot remember the identity of the user connected to a website, so the request for the web page is regarded as a unique and independent connection, unlike the one in it. The previous connection doesn't matter anyway - much like the behavior of many adventurous teenagers today, who drink all night and wake up the next morning with no memory of what happened. Go out at night and do the same thing over and over again...
Now, if you're aimlessly surfing from one site to another, no problem. But what happens when you want to buy a few books from Amazon.com? “In a stateless environment, remembering all the items on your shopping list is very difficult because of the statelessness of the HTTP protocol. The nature of the state makes it impossible to track selected items, so a way to make it possible to remember the state is required, something that can track the user's connection and save connection-specific data. cookie", which allows a Web site to save customer-specific information in a file on the customer's system and retrieve the information from the file whenever requested. So, in the shopping cart example above, the selected items can be added into the cookie and can be retrieved and presented in the shopping list when the consumer checks out.
There is a problem with the cookie-based solution, that is, it requires the cookie to be accepted by the customer. Another solution is to use "session", which is used to save a specific small piece of data when a client visits a Web site. This session data can be saved during the entire visit. Viewed as a message basket, it holds the host's variable pairs that exist throughout the visit and can be processed at any time. This approach provides a first-class solution to the stateless nature of the protocol. On many large websites today, information can be tracked and saved for personal and business transactions
Each created session has a unique identification string, which is sent to the client at the same time. An entry for the same unique identifier string is also generated on the server side, either in a text file or in a database. Now you can register any session variables - these ordinary variables can hold text or numerical information and can be read through the session.
Now, if you have followed the open source movement, you already know that PHP, the most popular scripting language on the planet, the latest version includes session support. Creation and management support, and in the following pages we'll show you how to use it. If you're still using PHP3, don't despair - we'll also cover PHPLIB, which includes a powerful set of PHP objects that can be used in Add seamless session management to PHP3-based sites
In the following pages, we assume that you already have a site that supports PHP4 or PHPLIB. If not, you should download these packages and install them. Install it on your development machine. PHP4, a high-quality code, can be found at the PHP site http://www.php.net, and the latest PHPLIB version can be found at http://phplib.netuse.de/.
http://www.bkjia.com/PHPjc/532660.html