In php.ini where can I set the default "secure" parameter value to true for the setcookie() call(): https://www.php.net/manual/en/function.setcookie.php#:~:text=match%20all%20subdomains.-,secure,-Indicates%20that%20the
Tried modifying session.cookie_secure but that seems to only apply to session cookie not regular cookies set by setcookie(…);
2
Answers
To set the default "secure" parameter value to true for the setcookie() function in PHP, you can use the session.cookie_secure directive in your php.ini configuration file. This directive controls whether cookies should only be sent over secure connections. However, this will affect all cookies, including those set by setcookie().
After updating this setting, you’ll need to restart your web server for the changes to take effect. Note that setting this directive to 1 will make cookies only be sent over secure connections (i.e., HTTPS).
As stated in the manual page,
setcookie()
already provides a default forsecure
and it’sfalse
:Having an INI parameter to override this would probably lead to endless head scratching.
Not sure what your exact concern is, but:
You don’t need to provide all other parameters if those defaults work for you:
You can use the newer signature and define your defaults in a central location:
You can write your own wrapper: