Session full tutorial (1) _ PHP Tutorial

Source: Internet
Author: User
Session full tutorial (1 ). What is a session? I didn't understand it at the beginning. non-professional dictionaries are translated into meetings and meeting periods. Make an inappropriate analogy (although not appropriate, it means the same). What is session? at the beginning, I don't understand it. non-professional dictionaries are translated into meetings and meetings. Make an inappropriate metaphor.
(Although inappropriate, it means the same thing). session is the relationship between you and your website. Session plays an important role in WEB technology. Because a web page is a stateless Connection program, you cannot know the browsing status of the user. Therefore, we must
The session is used to record user information for confirmation when the user requests the web server in this identity again. for example:
For example, users are often asked to log on to some websites, but how do we know that the user has logged on? if there is no session, the login information cannot be retained, do not provide the user name and password on each page.


Of course, sessions are not only used for user identity authentication, but may also be used in other aspects, as we will mention later. The session is interpreted as the session period in Chinese. A session starts when a user enters a website and ends when he leaves the website. Session was first introduced in the dynamic scripting language ActiveServerPages. it is powerful and cannot be clearly stated in one sentence.


When php is still in version 3.0, session is always a pain point. Although php has the advantages of fast execution speed, flexible use, and powerful functions, but due to session problems, many sites have abandoned php Development, at least my boss thinks so. At that time, many php free function libraries provided the solution to implement session on php3, but they all made people feel unauthentic. Just as if you spent thousands of oceans buying mobile phones but configured a rough grass bag, although the functions are the same, it is always awkward. The emergence of php4 gave PHP a chance to turn over the session issue. Although its session implementation is not ideal (mainly because of efficiency issues), it is implemented by itself and can be used in practice. What are we doing with session? if you have been talking about it for a long time and I cannot use it, wouldn't you sell paper. OK. Let's take a look at the usage of the session: all people who have made websites have such experiences. the variables on the page (in this chapter, they refer to server variables, the same below) it cannot be used on the next page. although some methods can be implemented, such as form and urlstring, it is inconvenient for some users, even if the form is automatically submitted, however, the latency is sufficient to suffocate people in today's network conditions, and both methods obviously increase the burden on programmers. If you are developing a large project, the extra burden cannot be ignored. With session, the variables registered in the session can be used as global variables. What are global variables? Great. In this way, you know what is used: mainly used for user identity authentication, Program Status record, and parameter transfer between pages.


After talking about the benefits of it for so long, you have already been tempted. Don't be happy first. it also has its disadvantages: it is a variable stored in a file (of course, the efficiency is not high, although it can be used in other ways, but it is very troublesome), the object cannot be saved. In contrast, sessions in asp can save object variables and use memory variables to save session variables. But why are we still using php? well, why? you should have understood this chapter from the beginning of this book. You still don't understand it, Faint, let's start from the beginning. I promise you will become a PHP expert ^_^.


How is the session implemented? Well, you must think it is very advanced. I will tell you its secret. If we only save variables, many readers understand that this is very simple, but as we have said before, http is a stateless connection. how do you know who the variable is, who is this variable? Cookie is used in session implementation. The cookie exists on the client, that is, the user's machine, which stores the user's sessionID, that is, the session number. when the user's browser requests the server, the sessionID is also sent to the server, in this way, the server can identify who you are, and the variable can be identified. In this way, we can easily understand why the session sometimes becomes invalid. If you don't believe it, you can try: there is an "Internet options" menu on the "Tools" menu of IE, and then choose "security"-> "custom level ", set "allow each session cookie" in the security settings to disabled and check whether the session can be used. Now, I understand! However, PHP4 can automatically check the cookie status on linux/unix platforms. when cookies are unavailable, sessionID is automatically included in the url for transmission. This is the only advantage of session over asp.

Bytes. Make an inappropriate analogy (although not appropriate, it means the same). session is...

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.