Cookies and sessions are familiar, especially cookies. in browsers, we often need to save the logon information to the corresponding cookies.
Cookies and sessions are familiar, especially cookies. in browsers, we often need to save the logon information to the corresponding cookies.
Cookie is mainly used on the client in PHP, and session is used on the server. Like the header () function, no output is allowed before use.
The setcookie () function is used to set a cookie value. It has six parameters: cookie name, cookie value, storage time, storage path, valid domain name, and HTTP Secure transmission. Generally, you can simply set a cookie using the first three parameters.
For example: setcookie ("TestCookie", $ value, time () + 3600 );
When a cookie is used, the following cookie value is called: echo $ _ COOKIE ['testcookie ']. In addition, $ _ COOKIE: print_r ($ _ COOKIE) can be printed );
Sometimes the cookie is to be destroyed, just like setting the cookie value. The value is null and the expiration time is in advance: setcookie ("TestCookie", "", time ()-3600 );
Array usage: similar information can be saved as an array to cookies: setcookie (NAME [he], 'Man '); setcookie (NAME [she], 'Woman ');
Print array: print_r ($ _ COOKIE ['name']);
Note that the cookie value cannot be an array or a string.