Home  >  Article  >  Backend Development  >  Conversation on the couch (1)_PHP tutorial

Conversation on the couch (1)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:19:33958browse

开始治疗

心理医生: 好。你今天感觉怎么样,维克多?

病人: 不太好,医生。我近来感到有点忧郁...

心理医生: 那是为什么,维克多?

病人: 我不知道,医生。我睡眠不太好,而且我一点胃口也没有。有一天我们去一个意大利餐馆,要了通心面 -- 但时当他们把它端上来的时候,我一点也吃不下去。我就一直看着它,在我的头里一直回荡着“女高音”的主题曲...

心理医生: 家里怎么样?

病人: 都很好,我想。Marge大部分时间都在厨房,试她从网上下载的菜谱。孩子们每天很早就出去了,一般在吃饭时才看得见他们,但是现在他们开始在Burger King吃了。那我也不能责备他们。

心理医生: 工作 - 都很好吧?

病人: 不太好 - 我有一个虐待成性的魔鬼老板,他打算打我的生活变成象Dilbert Zone一样!

心理医生: 跟我说一说他吧。

病人: 好,你知道我是做什么的 - 我是一个在Used Socks. Inc.的web程序员。下个星期我们的新网站就要使用了,我们正在做着完全不同的东西 -- 一个在线商店,供人们出售他们的旧物。我们得到了一些好心人的投资 - 6百万元,如果我们成为在web最受欢迎的旧物门户,我们还可得到更多的投资。

心理医生: 听上去对你不错嘛。

病人: 你说的对。但是,然后有一天老板进来,他说他交给我一项开发在线商店购物车的工作。他明确地要求我用什么叫“session”的东西。当然,只不过让事情变得有趣,他说他想在两天内做完并能运行...虐待狂、变态!

心理医生: 有问题吗?

病人: 有,特别是首先我根本不知道“session”是什么,或怎么去用它。我意思是说,我原以为一个session 就是对一个病人的短期治疗 -- 有一点象我们正在做的一样。

心理医生: 哦,维克多,维克多...这就是麻烦你的事吗?我想我可能有东西能帮助你...

西雅图无状态

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

truehttp: //www.bkjia.com/PHPjc/532660.htmlTechArticleStart treatment Psychologist: Okay. How are you feeling today, Victor? Patient: Not so good, doctor. I've been feeling a little depressed lately... Psychologist: Why is that, Victor? Patient...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn