In website construction, there are a lot of cookies, so how should we use cookies? How should we write cookies reasonably? below I will summarize the usage of cookies for your reference.
/**
@ Cookie learning
1. set cookie [setcookie (name, value, valid time, valid path, valid domain, and security)]
Setcookie () this function is part of the http header information, so there cannot be any output before use
Cookie: Array type
2. the cookie information can be the same as the normal array variable.
3. delete setcookie (name, value, Expiration Time ,'/')
Difference between session and cookie:
1. the former is stored on the server, and the latter is stored on the browser.
2. in terms of security, the former is safe, and the latter is not safe.
3. The latter has the path and domain name restrictions. the former does not
4. the use of Sessions depends on cookies. if cookies are disabled, a solution is required for the session.
5. the session is stored on the server. therefore, do not overuse the session to avoid heavy load on the server.
*/
Setcookie ('User _ name', 'hangsan ', time () + 3600 ,'/');
Setcookie ('User _ psd ', '000000', time () + 123456 ,'/');
Setcookie ('User _ addr ', 'Beijing', time () + 3600 ,'/');
// Setcookie ('User _ xueli ', 'daxue', time () + 3600, '/', '.phpone.com ');
// Setcookie ('User _ hobby', 'daxue ', time () + 3600,'/',' .phpone.com ', true );
// Use $ _ SERVER to view the system and Directory
// Print_r ($ _ SERVER );
Echo $ _ COOKIE ['User _ name'];
?>
/**
@ Delete cookie variable information
@ Give an expiration time
*/
Setcookie ('User _ name', 'abcd', time ()-1 ,'/');
Setcookie ('User _ addr ', 'abcd', time ()-1 ,'/');
Setcookie ('User _ psd ', 'abcd', time ()-1 ,'/');
?>