Home Backend Development PHP Tutorial Full session tutorial (1)_PHP tutorial

Full session tutorial (1)_PHP tutorial

Jul 13, 2016 pm 05:11 PM
session one Meeting I Tutorial what is Expect dictionary


What is session? I didn’t understand it at first. Non-professional dictionaries translate it as meeting and session 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
The user's relevant information is recorded through the session so that the user can confirm when providing a request to the web server again in this capacity, for example
For example, we often require 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 cannot be retained, so why not ask the user to provide the username on every page? name and password.


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 ActiveServerPages. Its function is so powerful that it cannot be explained clearly in one sentence.


When PHP was still in version 3.0, sessions were 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 it can be actually used. So what do we use session for? You've 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.


After talking about its benefits for so long, you are already tempted, but don’t be happy yet. It also has shortcomings: it is a variable saved in a file (of course it is not efficient, although other methods can be used, but it is very troublesome) , the object cannot be saved. In contrast, the session in asp can save object variables and use memory variables to save session variables. But why do we still use PHP? Haha, why, you can read this chapter from the beginning of this book, I guess you should understand it. If you still don’t understand, Faint, just start from the beginning again, I guarantee that you will become PHP expert ^_^.


How is session implemented? Haha, you must think it is very profound, let me tell you its secret. If you only save variables, many readers will understand that this is very simple, but as we said before, the http protocol is a stateless connection. How do you know who the variable belongs to and who the variable belongs to? ?Achieved using cookies in session implementation. The cookie exists on the client, that is, the user's machine. It stores the user's session ID, which is the session number. When the user's browser requests the server, the session ID is also sent to the server, so that the server can identify who you are. This way the variable can be identified. In this way, it is not difficult for us to understand why the session sometimes fails. If you don't believe it, you can try: There is the "Internet Options" menu on the "Tools" menu of IE. After opening it, select "Security"->"Custom Level" and change the "Allow use of each conversation" in the security settings. "Cookies" is set to disabled, and then see if the session can be used. Now you understand! However, PHP4 can automatically check the cookie status on the linux/unix platform. When the cookies are not available, the session ID will be automatically attached to the url and passed. This is its only advantage over asp in terms of sessions.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629569.htmlTechArticleWhat is session? I didn’t understand it at first. Non-professional dictionaries translate it into conference and session period. Let’s make an inappropriate metaphor (although it is inappropriate, the meaning is the same), session is...
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tutorial on how to use Dewu Tutorial on how to use Dewu Mar 21, 2024 pm 01:40 PM

Dewu APP is currently a very popular brand shopping software, but most users do not know how to use the functions in Dewu APP. The most detailed usage tutorial guide is compiled below. Next is the Dewuduo that the editor brings to users. A summary of function usage tutorials. Interested users can come and take a look! Tutorial on how to use Dewu [2024-03-20] How to use Dewu installment purchase [2024-03-20] How to obtain Dewu coupons [2024-03-20] How to find Dewu manual customer service [2024-03-20] How to check the pickup code of Dewu [2024-03-20] Where to find Dewu purchase [2024-03-20] How to open Dewu VIP [2024-03-20] How to apply for return or exchange of Dewu

Tutorial on how to turn off the payment sound on WeChat Tutorial on how to turn off the payment sound on WeChat Mar 26, 2024 am 08:30 AM

1. First open WeChat. 2. Click [+] in the upper right corner. 3. Click the QR code to collect payment. 4. Click the three small dots in the upper right corner. 5. Click to close the voice reminder for payment arrival.

What software is photoshopcs5? -photoshopcs5 usage tutorial What software is photoshopcs5? -photoshopcs5 usage tutorial Mar 19, 2024 am 09:04 AM

PhotoshopCS is the abbreviation of Photoshop Creative Suite. It is a software produced by Adobe and is widely used in graphic design and image processing. As a novice learning PS, let me explain to you today what software photoshopcs5 is and how to use photoshopcs5. 1. What software is photoshop cs5? Adobe Photoshop CS5 Extended is ideal for professionals in film, video and multimedia fields, graphic and web designers who use 3D and animation, and professionals in engineering and scientific fields. Render a 3D image and merge it into a 2D composite image. Edit videos easily

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

Experts teach you! The Correct Way to Cut Long Pictures on Huawei Mobile Phones Experts teach you! The Correct Way to Cut Long Pictures on Huawei Mobile Phones Mar 22, 2024 pm 12:21 PM

With the continuous development of smart phones, the functions of mobile phones have become more and more powerful, among which the function of taking long pictures has become one of the important functions used by many users in daily life. Long screenshots can help users save a long web page, conversation record or picture at one time for easy viewing and sharing. Among many mobile phone brands, Huawei mobile phones are also one of the brands highly respected by users, and their function of cropping long pictures is also highly praised. This article will introduce you to the correct method of taking long pictures on Huawei mobile phones, as well as some expert tips to help you make better use of Huawei mobile phones.

PHP Tutorial: How to convert int type to string PHP Tutorial: How to convert int type to string Mar 27, 2024 pm 06:03 PM

PHP Tutorial: How to Convert Int Type to String In PHP, converting integer data to string is a common operation. This tutorial will introduce how to use PHP's built-in functions to convert the int type to a string, while providing specific code examples. Use cast: In PHP, you can use cast to convert integer data into a string. This method is very simple. You only need to add (string) before the integer data to convert it into a string. Below is a simple sample code

Meetings can now be held using DingTalk on WeChat Meetings can now be held using DingTalk on WeChat Mar 05, 2024 pm 03:10 PM

This site reported on March 4 that DingTalk, owned by Alibaba, has received the iOS version 7.5.10 update, which supports browsers to directly enter DingTalk meetings. The log shows that by clicking on the DingTalk video conference joining link in WeChat or an external browser, you only need to verify your mobile phone number to join the meeting, making the meeting more convenient. Tested by this site, the DingTalk meeting function in WeChat currently only has a few core functions such as switching the microphone, switching the camera, inviting friends, and viewing members. To join the meeting for the first time, you need to enter a mobile phone number verification code. If you enter the meeting again within the next 30 days, you can achieve the same goal. Key shortcut login. The following is the updated content of DingTalk iOS version 7.5.10: [Attendance punch-in: shift supports setting multiple break times] Supports the attendance punch-in shift function of setting multiple break times, which is suitable for long-term work,

Laravel Redis Tutorial: Quickly Master Usage Laravel Redis Tutorial: Quickly Master Usage Mar 09, 2024 pm 03:06 PM

LaravelRedis Tutorial: Quickly master usage, specific code examples are required. In modern web development, caching is one of the important means to improve website performance. As a high-performance in-memory database, Redis is widely used in various web applications. In this tutorial, we will introduce how to use Redis in the Laravel framework to improve performance and expand functionality. 1. Install Redis Before starting, first make sure that the Redis service has been installed in your development environment. you can

See all articles