The cookie is saved on the browser side, php Data can be saved on the browser by issuing a command.
Use firebug to go to the network panel to monitor the requests sent by the browser and the responses received:
In the response data, the browser that sends the data should tell the browser to save the cookie variable:
The server uses part of the response data (response header) to send the set cookie information to the browser:
Viewing The request data sent by the browser carries the cookie that the browser considers valid to the server.
At this time, the server received the request and found that cookie data existed. This data was used to form the $_COOKIE array for use by user scripts.
Session and cookie solve the same problem.
Get a method that can pass data in multiple requests from the same browser.
Data is stored directly on the browser side. There are two obvious problems:
On the server, save the data.
How to ensure that data can be passed between multiple requests of the browser and distinguish between browsers.
On the server side, create an independent data space for each visiting browser. Assign a unique identifier to each data space and let the browser save this unique identifier. Every time the browser makes a request, it carries the identifier and uses the identifier to determine the unique data space.
Session technology: The session data is saved on the server side, and the browser side saves the storage data space identifier. The browser carries the identifier when requesting, and the server is responsible for using the identifier to perform data processing in the corresponding storage space.
| 2
3
4
5
6
7
8
|
| table>
Tips; session technology is based on cookie technology and needs to save the identifier in the cookie
When the session is opened, the server will assign a cookie variable to the browser to save the sessionID (identification of the session), and save it to the browser device end.
Tips: It is a cookie variable that is valid for the entire site
In the next request of the browser, the cookie variable and sessionID are carried to the server:
Default: PHP saves each independent data space in the form of a file. It is saved in the temporary directory of the server system.
The file name is named after the current session ID to ensure spatial uniqueness.
It can be seen that when saving, it is the result of the deterioration of academic qualifications.
Two basic steps:
Only the elements of $_SESSION in the following table can be numeric.
| 2
|
|
unset($_SESSION['key']); delete an element in $_SESSION
What if all session data is deleted?
$_SESSION = array();
Incorrect: unset($_SESSION); will not cause session data to be lost. PHP’s internal session mechanism can also find existing processed session data and write it to the session data space.
Delete session-related storage files
session_destroy() function can be completed
However, if the file is deleted, the data in the $_SESSION array is still there:
However, after executing session_destroy(), the write operation after the script cycle will not be executed.
How to completely delete all data of a session?
File, $_SESSION, sessionID variable in cookie
session_destroy();
$_SESSION = array();
setcookie('PHPSESSID','',time() - 1);
Typically complete by executing session_start()
Supported, automatically enabled in configuration file
However, if the session is opened repeatedly, an error will be reported:
Typically just mask the errors
can be configured:
The session data processing method used by session.save_handler php
can be changed to user, indicating user customization
session.save_path
Different storage locations
Low sensitivity, data that needs to be saved permanently is stored in cookies (user experience)
High security, the data existing during the session period is saved in the session (data legality, rationality, integrity)
session can save various data types
Typically save the login verification logo into the session:
application/controller/back/AdminController.class.php
| 2
3
4
5
6
7
8
9
10
11
12
|
} } span> |
application/controller/back/IndexController.class.php
Record login status
After successful login, determine whether you have chosen to save the login information:
application/controller/back/AdminController.class.php
signinAction()
What format to record:
Confidential and can be verified
Cannot save, background login information
Must be at least a pair and can be verified
Designed to:
admin_id
Processed password (encrypted on the basis of md5)
| 2
3
4
5
|
setcookie(}
| 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
$result = $model_admin->checkByCookie(); $session_start(); } } } |
| application/controller/back/IndexController.class.php
indexAction()
| 2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
$result = $model_admin->checkByCookie(); span [ } } } |
Model
Add a checkByCookie() method in AdminModel:
application/model/AdminModel.class.php
http://www.bkjia.com/PHPjc/626631.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/626631.htmlTechArticle (to reduce the burden on the entry file and move the functions implemented by the entry file into the basic class of the framework) In the framework directory Add Framework.class.php plan: public functions that need to be initialized, split the model...