: This article mainly introduces PHP-cookie. if you are interested in the PHP Tutorial, you can refer to it.
The server tracks and stores user data, which exists in the HTTP header and is stored in the global variable $ _ COOKIE.
Identify users
Setcookie function
Name $ _ COOKIE ['name'] accessible
Value
Expire expiration time
Path valid path,/the entire website takes effect
Domain valid domain by default, the entire domain name is valid
Restrictions on using cookies
- The cookie is not too secure and is prone to theft, resulting in cookie spoofing.
- The maximum value of a single cookie is 4 kB.
- Network transmission is required for each request, occupying the bandwidth
- Cookie only supports string type
Session
Session_start () enabled
Global variable _ $ SESSION is used to save session data and save it on the server as a file (cookie is saved on the client)
When the page is opened, this session file is exclusive, causing other concurrent accesses of the current user to be unable to be executed and waiting. it can be stored as a cache or database.
Unset () deletes a session value.
Session_destroy () deletes all data, but session_id still exists. The deletion mechanism is to delete session data the next time you access it.
10000, 'name' => 'Spark ', 'Email' => 'spark @ imooc.com ', 'sex' => 'Man ', 'age' = & gt; '18'); header ("content-type: text/html; charset = utf-8 "); /* save user information to the session */$ _ SESSION ['uid'] = $ userinfo ['uid']; $ _ SESSION ['name'] = $ userinfo ['name']; $ _ SESSION ['userinfo'] = $ userinfo; // * a simple method for saving user data to cookies */$ secureKey = 'imooc '; // encryption key $ str = serialize ($ userinfo ); // serialize user information // $ str = base64_encode (mcrypt_encrypt (MCRYPT_RIJNDAEL_256, md5 ($ secureKey), $ str, MCRYPT_MODE_ECB) before user information encryption )); // after the user information is encrypted // The encrypted user data is stored in the cookie setcookie ('userinfo', $ str ); // when necessary, decrypt $ str = mcrypt_decrypt (encrypt, md5 ($ secureKey), base64_decode ($ str), MCRYPT_MODE_ECB); $ uinfo = unserialize ($ str ); echo "decrypted user information:
"; Print_r ($ uinfo );
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces PHP --- cookie, including some content, and hope to help friends who are interested in PHP tutorials.