Php -- session control, php session
1. What is session control?
Allows the server to make consecutive requests based on the client.
2. Why is session control required?
Because when you open a website and want to access other pages of the website, if there is no session control, you need to enter your account and password again when you jump to other pages.
3. principles and functions of cookies
Save the simple information of the client in the personal PC. Other programs obtain the Cookie of the PC to obtain the user's information. In this way, you do not need to enter your account and password.
Note: setCookie () must be used before php outputs the first sentence; otherwise, it is invalid.
4. How to Use Cooike (General)
Create Cookie
SetCookie ("key", "value", retainTime); // create a Cookie
Call Cookie
If ($ _ COOKIE ["key"] = "admin") {// Cookie is the Super array echo provided by php "data retrieved ";}
Delete Cookie
// The first method setCookie ("key"); // you only need to enter the key name. // The second method setCookie ("key", "", time () -1000); // make the retention time less than the current time
Cookie can be changed to a multi-dimensional array
SetCookie ("user [key]", "values"); // equivalent to $ _ COOKIE ["user"] ["key"]
Simple Example: Cookie-Based User Login
5. principles and functions of sessions
Store information on the server rather than on a personal PC.
6. How to Use Session
(1). Configure the php. ini option (do not expand, and query relevant documents by yourself)
(2). Start the session
Session_start (); // you must call this method before using session.
Purpose: Load Session-related built-in environment variables into the memory in advance.
(3) Call
$ _ SESSION ["key"] = "value"; // $ _ SESSION is also a super array and called as an array
(4) Delete
// Delete a single unset ($ _ SESSION ["key"]); // delete all $ _ SESSION = array (); // set it to an empty array // Delete session_destory () from the Session file corresponding to the user on the server ();