: This article mainly introduces the summary of cookies and Sessions. For more information about PHP tutorials, see.
|
|
|
|
|
|
|
|
|
|
|
|
|
Cookie |
Session
|
Storage location
|
Stored in a browser |
Real files exist on the server
, K exists in the browser |
Security
|
Low, easy to forge |
Higher than cookie security |
Set
|
Setcookie () function |
Session_start ()
Function operations |
Storage type
|
Scalar type: int, float, char, bool, null |
All types except resources |
Lifecycle
|
Set through the third parameter
For example, setcookie ('school ', 'xtu', time () + 15 );
|
Use the php. ini file to set
Session. cookie_lifetime
Session. gc_maxlifetime
|
Valid Path
|
Set through the fourth parameter
Setcookie ('school ', 'kefeng', time () + 5 ,'/');
|
Depends on the valid cookie path
Php. ini can be configured as follows:
Session. cookie_path =/
|
Valid domain name
|
Set through the fifth parameter
String'Www .example.com'
|
Depends on the valid domain name of the cookie
Php. ini can be configured as follows:
Session. cookie_domain =
|
Read
|
$ _ COOKIE [''] |
$ _ SESSION [''] |
Destroy
|
Setcookie (",", 0)
Setcookie (",", time ()-1)
|
Four destruction methods:
1. destroy a unit:
Unset ($ _ session ['school']);
2. Overall cleanup:
$ _ Session = array ();
3. clear all functions:
Session_unset ();
4. no boxes are needed:
Session_destory ()
|
| Principle |
Between browsers and servers
Server load balancer
Data transmission through HTTP headers
Next intercommunication with the browser Carry the HTTP header to the server |
Store K in this process
(Number of browsers to servers
Data interaction) V is stored on the server
In the process The data for server interaction is K. |
The above section describes the summary of cookies and sessions, including related content, and hopes to help those who are interested in PHP tutorials.