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!