我想在通过 HTTPS 访问内容时为 cookie 数据设置安全标志。
cookie 用于整个应用程序,因此需要全局配置以保护所有 cookie。
最佳答案
您需要使用 session_set_cookie_params
覆盖默认设置,将 $secure 标志设置为 true,
void session_set_cookie_params ( int $lifetime [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]] )
更多信息请访问 php.net
在 laravel 中你需要修改 config/session.php 配置,将 secure flag 设置为 true
/*
|--------------------------------------------------------------------------
| HTTPS Only Cookies
|--------------------------------------------------------------------------
|
| By setting this option to true, session cookies will only be sent back
| to the server if the browser has a HTTPS connection. This will keep
| the cookie from being sent to you if it can not be done securely.
|
*/
'secure' => true,
在较新版本的 laravel 中,您只需在 .env
文件中设置 SESSION_SECURE_COOKIE=true
关于php - 如何在 laravel 的 cookie 上设置安全标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47299809/