secure决定了cookie是否可以通过HTTP协议的URL设置
php通过setcookie来设置cookie,具体参数如下
setcookie(
string $name,
string $value = "",
int $expires = 0,
string $path = "",
string $domain = "",
bool $secure = false,
bool $httponly = false
): bool
HTTP协议
URL:http://www.test.com/test.php
setcookie('test','this is a test',0, '/','www.test.com',true)
此时设置cookie失败,在客户端是无法找到名为test的cookie。
setcookie('test','this is a test',0, '/','www.test.com',false)
此时设置cookie成功。
HTTP协议下,secure只有为false才能设置cookie。
HTTPS协议
URL:https://www.test.com/test.php
setcookie('test','this is a test',0, '/','www.test.com',true)
setcookie('test','this is a test',0, '/','www.test.com',false)
两种方式均可设置cookie成功。
HTTPS协议下,secure为true或者false,不影响cookie设置。