1, set a cookie
? < PHP the setcookie ( ' Key ' ); the setcookie ( ' key1 ' , ' VALUE1 ' ); the setcookie ( ' key2 ' , ' value2 ' , Time () + . 1 * 24 * 60 * 60 );
the setcookie ( 'KEY4', 'value4', time () + 1 * 24 * 60 * 60, '', '', false, true); // Once the cookie httponly is true, you can only get on the server side, js inoperable
① only pass a parameter is deleted, the principle: set the expiration time of a bygone time
② passed two parameters are set cookie
③ pass a third argument is to set the expiration time, that does not pass session-level cookie (closing the browser will be automatically deleted);
④ setting response Set-Cookie headers can be issued small ticket (to the client)
⑤Cookie stored in the client is the key structure
⑥header set in the same key, the situation will be covered
header('key1' , 'value1');
header('key2', ' value2');
⑦setcookie function is designed to set a cookie
2, get cookie (associative array of ways to access the client submitted over Cookie)
<?php
var_dump($_COOKIE);
Print Results:
array(2) { ["key1"]=> string(6) "value1" ["key2"]=> string(6) "value2" }
3, the role of the cookie and other common concept
①path set a cookie path of action range
/: As long as all the connection address in the web root directory you can access this cookie
/ Users: only path to the directory in the users access
②domain role in setting the cookie domain range
site7.io: All site7.io subdomains are accessible to
--www.site7.io √
--foo.site7.io √
--site6.io ×