Php -- Session Control, php session. Php -- Session Control, php session 1. what is session control that allows the server to make continuous requests based on the client. 2. Why is session control required? Because when you open a website, 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 ();
Protocol 1. what is session control that allows the server to send consecutive requests based on the client. 2. Why is session control required? Because when you open a website ,...