What is Session?

Source: Internet
Author: User
First, explain what Session is, if you do not know. When a visitor arrives at your website, a Session begins, and when he leaves, the Session ends. In essence, cookies are related to browsers, and Session variables can store some resource variables on servers. PSyntaxHighlighter

First, explain what Session is, if you do not know. When a visitor arrives at your website, a Session begins, and when he leaves, the Session ends. In essence, cookies are related to browsers, and Session variables can store some resource variables on servers. PHP4 uses files to store Session variables, but theoretically it can be done using databases or shared memory. All pages use the PHP4 Session function Session_start () to tell the PHP4 engine to fetch the relevant Session to the memory. The Session_start () function can be used to obtain the Session_id in the cookie domain or request parameters in response to the http request. If the SessionID cannot be found, a new Session is created. What is a Session variable? A Session variable is a regular global variable. when a Session variable is registered, you can use PHP4 to obtain the Session value on all pages. You can use Session_register ("variable_name") to register a Session variable. The Session_start () function is used for all concurrent sessions. The value of the variable is registered as a Session variable. What can we do? There are usually many ways to manage Session and Session variables. I will give you an example. Say that you will build a commercial site, such as me, you may want to keep the current name of the recognized user, or how many new message users have obtained. In order not to read data from the database, you have two methods: 1. 1. you can use three cookies. Authenticated_user-current user name. Num_messages-the number of information obtained by num_messages. Expire_time-when to re-read information 2. 2. it is difficult to use sessions and the first method to create three session variables. some people can get cookies to access other people's fields. With sessions, users get only one cookie, which is much safer. The disadvantage is that the session gives you freedom. excessive use of the session will affect the use of the script language. Although the session of PHP4 has some limitations, for example, you cannot store objects in the session. Give it a try!

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.