SESSION management in PHP4 _ PHP Tutorial

Source: Internet
Author: User
SESSION management in PHP4. The most notable new feature of PHP4 is the SESSION management function. when others visit your site, you can save the variables to the SESSION object to implement many new functions. what is the most striking new feature of PHP4 is the SESSION management function. when others visit your site, you can save the variables to the SESSION object to implement many new functions.
What is SESSION?
If you are not quite clear, let me explain what SESSION is. a session starts when someone else accesses your website and ends when someone else leaves the website. of course, you can terminate it in the program. basically, cookies are associated with browsers. resources on some servers are used to save SESSION variables. by default, PHP4 uses files to save these variables. of course, theoretically, it can also be saved using a database or shared memory.
All web pages that use the SESSION feature of PHP4 must call the session_start () function to load SESSION-related information to the PHP4 engine in the memory. the session_start function will try to find the session id from the COOKIE or the parameters of the current HTTP request. if not found, a new SESSION object will be created.
What is SESSION variable?
The SESSION variable is actually a common global variable. when a SESSION variable is registered (declared), all webpages using the SESSION function of PHP4 can access its value. to register a variable as a SESSION variable, assign a value to the variable and call session_register ("variable name "). in the subsequent Web pages that use the SESSION function (through session_start), the variable "variable name" does not need to be re-registered as the SESSION variable. it is like a common variable, and its value is previously assigned to it. if you change the value of this variable in the program, it will automatically register and save it, and it can be used normally in subsequent web pages.
So what can it do?
Good question! There are many ways to use SESSION management and SESSION variables. here is an example. if you are building a virtual community site, you may want to track the username demonstrated and how many new messages are there. to reduce the load on the database, you need to save the information in other ways. there are two methods:
Use three cookies
Authenticatied_user-currently demonstrated user name
Num_message-how many new messages does it have?

Expire_time-COOKIE expiration time limit
Use SESSION to register three SESSION variables
The first method has a great security risk. someone else can forge a COOKIE and then use another account to access the system. besides, all information is implemented through the HEADER () function, which is troublesome. in addition, when the user's browser refuses to accept one of the cookies, the entire data is incomplete.
With SESSION, all the information can be saved as long as one COOKIE. the security is even better.
Weaknesses
SESSION can provide a very free, flexible, and powerful function using any script language on the server. however, the SESSION in PHP4 has some limitations:-the object itself cannot be saved in the SESSION.-The efficiency of data stored in the SESSION is not very high, because PHP4 uses a file to save SESSION information.

You can save the variables to the SESSION object to implement many new functions. what 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.