1717use CodeIgniter \HTTP \Exceptions \HTTPException ;
1818use CodeIgniter \Pager \PagerInterface ;
1919use CodeIgniter \Security \Exceptions \SecurityException ;
20+ use Config \Cookie as CookieConfig ;
2021use Config \Services ;
2122use DateTime ;
2223use DateTimeZone ;
@@ -544,8 +545,8 @@ public function redirect(string $uri, string $method = 'auto', ?int $code = null
544545 * @param string $domain Cookie domain (e.g.: '.yourdomain.com')
545546 * @param string $path Cookie path (default: '/')
546547 * @param string $prefix Cookie name prefix ('': the default prefix)
547- * @param bool $secure Whether to only transfer cookies via SSL
548- * @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
548+ * @param bool|null $secure Whether to only transfer cookies via SSL
549+ * @param bool|null $httponly Whether only make the cookie accessible via HTTP (no javascript)
549550 * @param string|null $samesite
550551 *
551552 * @return $this
@@ -557,8 +558,8 @@ public function setCookie(
557558 $ domain = '' ,
558559 $ path = '/ ' ,
559560 $ prefix = '' ,
560- $ secure = false ,
561- $ httponly = false ,
561+ $ secure = null ,
562+ $ httponly = null ,
562563 $ samesite = null
563564 ) {
564565 if ($ name instanceof Cookie) {
@@ -567,8 +568,17 @@ public function setCookie(
567568 return $ this ;
568569 }
569570
571+ /** @var CookieConfig|null $cookieConfig */
572+ $ cookieConfig = config ('Cookie ' );
573+
574+ if ($ cookieConfig ) {
575+ $ secure ??= $ cookieConfig ->secure ;
576+ $ httponly ??= $ cookieConfig ->httponly ;
577+ $ samesite ??= $ cookieConfig ->samesite ;
578+ }
579+
570580 if (is_array ($ name )) {
571- // always leave 'name' in last place, as the loop will break otherwise, due to $$item
581+ // always leave 'name' in last place, as the loop will break otherwise, due to ${ $item}
572582 foreach (['samesite ' , 'value ' , 'expire ' , 'domain ' , 'path ' , 'prefix ' , 'secure ' , 'httponly ' , 'name ' ] as $ item ) {
573583 if (isset ($ name [$ item ])) {
574584 $ {$ item } = $ name [$ item ];
0 commit comments