First of all, it is stated that the browsing cookie operation is implemented through the HTTP header (commonly known as the "HTTP Header"). All the cookie data transfers between the server and the client are done through the HTTP request header.
PHP Setcookie (function Implementation), is the HTTP header encapsulation, which seems to use the header and the use of Setcookie is the same.
Because header information belongs to HTTP protocol content, you must first send the head information to the server, then data download and other operations, so there is no content output before Setcookie and header (for example: echo/printf, etc.)
Header Set Cookie method:
| 1 |
Header ("Set-cookie:testcookie= Chinese"; path=/; domain=.sunphp.org; Expires= ". Gmstrftime ("%A,%d-%b-%y%h:%m:%s GMT", Time () + 9600)); |
Setcookie Setup mode:
Syntax: Setcookie (name,value,expire,path,domain,secure)
Cases:
| 1 |
Setcookie ("website", ' www.sunphp.org ', time () + 3600 * 24); |
| parameter |
description |
| name |
required. Specify the name of the cookie. |
| value |
is required. Specify the value of the cookie. |
| expire |
is optional. Specify the expiration date of the cookie. |
| path |
is optional. Specify the server path for the cookie. |
| domain |
is optional. Specify the domain name of the cookie. |
| secure |
is optional. Specify whether to transmit cookies through a secure HTTPS connection. |