Session full Tutorial (i) _php tutorial

Source: Internet
Author: User
What session is, at first I also do not understand, non-professional dictionary translation for the Conference, the Conference period. Make a less appropriate metaphor.
(although inappropriate, but the meaning is the same), the session is the relationship between you and the site. Session plays a very important part in Web technology. Because a Web page is a stateless connection, you cannot know the user's browsing status. So we must
The user's information is logged through the session, so that the user is asked to provide the Web server with this identity
For example, we often ask users to log in on some websites, but how do we know that the user has logged in, if there is no session, the login information is not retained, it is not to let users on every page of the Web page to provide a user name and password.


Of course, the session is not only for the user authentication function, but also may be used in other aspects, we will mention later. The session is interpreted in Chinese as a conversation period. A session period begins when the user enters the URL of a site and ends when he leaves the site. The session first appeared in the Dynamic scripting language activeserverpages, its powerful function, is a sentence can not be said clearly.


When PHP is still in version 3.0, the session is always painful. Although PHP has the performance of fast, flexible, powerful and other advantages, but because of the session of the problem, so many site development abandoned PHP, at least my boss think so. There were a lot of PHP free libraries that offered the option to implement the session on the PHP3, but all of them felt not authentic. It's like you're spending thousands of of dollars on a mobile phone but a very coarse grass bag, although the function is the same, but always feel awkward. The advent of PHP4 has given PHP a chance to roll over the session. Although its session implementation is not ideal (mainly in terms of efficiency), but it is its own implementation, and can be used in practice. Then what do we do with the session, you say for a long while, I do not use words, you do not have to sell paper suspicion. OK, let's see what the session is for: People who have made the site have this experience, in a page of the variable (in this chapter refers to server-side variables, the same below) is not available on the next page, although there are some ways to achieve, such as with form,urlstring, etc., But some of the users are inconvenient, even if the form is automatically submitted, but the delay in the current network conditions are enough to suffocate, and both of these methods significantly increase the burden on the programmer. If you are developing a large project, these additional burdens cannot be overlooked. And with the session is good to do, the variables registered in the session can be used as a global variable. What, global variables? great. In this way, you know what is the use of it: the most important for user authentication, program status records, the parameters passed between pages.


Said it so half of the benefits, you have been tempted to do it, don't be happy, it also has shortcomings: it is a file saved variables (of course, although the efficiency is not high, though can be used in other ways, but very troublesome), can not save the object. In contrast, the session in the ASP can hold object variables and memory variables to hold session variables. But why we also choose PHP, hehe, why, you can see this chapter from the beginning of this book, presumably you should also understand, you do not understand, faint, you look at the beginning again, I guarantee you become a PHP expert ^_^.


How is the session implemented? Oh, you must think very advanced, I come to tell you its secret. If we just save the variables, many readers understand that this is very simple, but as we said earlier, the HTTP protocol is a stateless connection, how do you know who the variable is, and whose is it? implemented in session with a cookie. Cookies exist in the client, that is, the user's machine, which holds the user's SessionID, that is, the session number, when the user's browser requests the server SessionID also sent to the server, so that the server can identify who you are, It is also possible to identify the variable. This makes it easy to understand why the session sometimes fails. If you do not believe, you can try: on the IE "Tools" menu has the "Internet Options" menu, open and then select "Security", "Custom Level", the security settings in the "Allow use of each chat cookies" set to disable, and then see if the session can be used. That's clear! However, PHP4 can automatically check the status of cookies on the Linux/unix platform, and when the cookies are not available, it will automatically pass the SessionID to the URL. This is the only advantage of it in terms of the session more than ASP.

http://www.bkjia.com/PHPjc/629569.html www.bkjia.com true http://www.bkjia.com/PHPjc/629569.html techarticle What session is, at first I also do not understand, non-professional dictionary translation for the Conference, the Conference period. Make a less appropriate metaphor (though inappropriate, but the meaning is the same), the 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.