Conversation posted in Changsha (1) _ PHP Tutorial

Source: Internet
Author: User
Conversation posted in Changsha (1 ). Start treating a psychiatrist: good. How do you feel today, Victor? Patient: not good, doctor. I 've been feeling a little depressed recently... why is that, Victor? Patient Start treatment

Psychologist: good. How do you feel today, Victor?

Patient: not good, doctor. I feel a little depressed recently...

Psychologist: why is that, Victor?

Patient: I don't know, doctor. I don't have a good sleep, and I have no appetite at all. One day we went to an Italian restaurant and asked for macaroni -- but when they brought it up, I couldn't eat at all. I watched it all the time, and in my head I always echoed the "female" theme song...

Psychologist: how is the family?

Patient: they are all good, I think. Marge spent most of her time in the kitchen and tried the recipe she downloaded from the Internet. The children went out early every day and usually saw them at dinner, but now they started eating at Burger King. Then I cannot blame them.

Psychology doctor: work-all right?

Patient: not very good-I have an abusive devil boss who plans to beat me and turn my life into the same way as Dilbert Zone!

Psychologist: Tell me about him.

Patient: Well, you know what I do-I am a web programmer at Used Socks. Inc. Next week our new website will be used. we are doing something totally different-an online store for people to sell their old things. We get some good-hearted people to invest-6 million yuan. if we become the most popular old thing portal on the web, we can get more investment.

Psychologist: It sounds good to you.

Patient: You are right. However, one day the boss came in and said he gave me a job to develop a shopping cart in an online store. He explicitly asked me to use something called "session. Of course, it just makes things interesting. He says he wants to finish and run things in two days... crazy, abnormal!

Psychologist: Is there a problem?

Patient: Yes, especially first, I don't know what the "session" is or how to use it. I mean, I thought a session would be short-term treatment for a patient-something that we were doing.

Psychologist: Oh, Victor, Victor... is that a problem for you? I think I may have something to help you...

Stateless Seattle

In order to impress young women who can hear conversations, simple joke people often say: "HTTP is a stateless protocol, the Internet is a stateless development environment ". In simple terms, the HTTP (HyperText Transfer Protocal) protocol, as the backbone of the web, cannot remember the identity of a user connected to a website, therefore, a request to a web page is considered as a unique and independent connection, it has nothing to do with the connections before it -- this is very similar to the behavior of teenagers who love adventure today. do they drink everyday? The next morning, I woke up and couldn't remember what happened. I went out to do the same thing at night, over and over again...

Now, if you are surfing from one site to another with no aim, there is no problem. But what if you want to buy a few books from Amazon.com? "In a stateless environment, it is very difficult to remember all the items on your shopping list, because the stateless nature of HTTP makes it impossible to track selected items.

Therefore, a method is required to make it possible to remember the status, and to track user connections and save things that connect to specific data. Therefore, a "cookie" is generated, which allows the Web site to store customer-specific information in a file of the customer's system and retrieve information from the file whenever requested. Therefore, in the preceding shopping cart example, the selected item can be added to the cookie, and can be taken out and displayed in the shopping list during consumer checkout.

There is a problem with the cookie-based solution, that is, it requires the cookie to be accepted by the customer. Therefore, another solution is to use "session" to store a specific small piece of data when a customer accesses a Web site. The session data is saved during the entire access period. A session can be considered as an information basket, which stores the host variable pair. These variables exist throughout the access period and can be processed at any time. This method provides a first-class solution to the stateless features of the protocol, and today many large websites can track and store information for personal and commercial transactions.

Each created session has a unique identifier string sent to the client. at the same time, the server generates an entry for the same unique identifier string, or put it in a text file or in a database. Now you can register any session variables-these common variables can save text or numerical information and can be read or written through the session.

Now, if you have followed the open source code movement, you already know PHP, the most popular scripting language on the planet. The latest version is PHP4, which supports session creation and management. in the following pages, we will show you how to use it. If you are still using PHP3, don't be disappointed-we will also involve PHPLIB, which includes a group of powerful PHP Objects that can be added to the PHP3-based site for seamless session management.

On 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 on your development machine. PHP4, is a quality code, can be found in the PHP site http://www.php.net, the latest PHPLIB version can be found at http://phplib.netuse.de.


Yan psychology doctor: good. How do you feel today, Victor? Patient: not good, doctor. I 've been feeling a little depressed recently... why is that, Victor? Patient...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.