Home  >  Article  >  Backend Development  >  1. Session Overview_PHP Tutorial

1. Session Overview_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:05:06899browse

1. Overview of session
I didn’t understand what session was at the beginning. Non-professional dictionaries translate it into meeting and meeting period. Let’s make an inappropriate metaphor
(although inappropriate, the meaning is the same), session is the relationship between you and the website.
Session plays a very important role in WEB technology. Since the web page is a stateless connection program, you cannot know the user's browsing status. Therefore, we must
record the relevant information of the user through the session so that the user can confirm when providing a request to the web server again in this capacity. For example,
we often require users to log in on some websites, but how do we Knowing that the user has logged in, if there is no session, the login information cannot be retained, then why not ask the user to provide a user name and password on every web page.

Of course, session is not only used for user identity authentication, but may also be used for other aspects, which we will mention later.
Session is explained in Chinese as session period. A session begins when the user enters the URL of a site and ends when he leaves the site. Session first appeared in the dynamic scripting language Active Server Pages. Its function is so powerful that it cannot be explained clearly in one sentence.


When PHP was still in version 3.0, session was its eternal pain. Although PHP has the advantages of fast execution speed, flexible use, and powerful functions, many website developers have abandoned PHP because of session problems, at least my boss thinks so. At that time, there were many PHP free function libraries that provided solutions for implementing sessions on PHP3, but they all felt unauthentic. It's like the mobile phone you bought for thousands of dollars comes with a rough straw bag. Although the functions are the same, it always feels awkward. The emergence of php4 has given PHP a chance to make a comeback on the session issue. Although its session implementation is not ideal (mainly due to efficiency issues), it is implemented by itself after all and can be actually used.
Then what do we use session for? You have been talking for a long time. If I don’t use it, wouldn’t you be suspected of selling paper? OK, let’s see what the session is used for: Anyone who has worked on a website has this experience. The variables on one page (in this chapter all refer to server-side variables, the same below) cannot be used on the next page. Although there are some ways to achieve this, such as using forms, urlstrings, etc., some are inconvenient for users. Even if the form is automatically submitted, the delay is enough to suffocate under today's network conditions, and this Both methods significantly increase the burden on programmers. If you are developing a large project, these additional burdens cannot be ignored. With session, it is easier to handle. Variables registered in session can be used as global variables. What, global variables? Great. In this way, you know what it is used for: the most important ones are used for user identity authentication, program status recording, and parameter transfer between pages.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445155.htmlTechArticle1. Overview of session What is session? I didn’t understand it at first. Non-professional dictionaries translate it to conference, conference period . Let’s make an inappropriate metaphor (although it is inappropriate, the meaning is the same...
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