diff options
author | George Petculescu <gxgpet@gmail.com> | 2021-04-02 01:41:29 +0200 |
---|---|---|
committer | George Petculescu <gxgpet@gmail.com> | 2021-04-02 01:41:29 +0200 |
commit | 0cf5aa1a17bf0fd91797a943b8e696a454f5d326 (patch) | |
tree | f06da461f3a771988915cc0ec7422c1f7039f22d | |
parent | 4f6d9ba5b6b690f3b7b30c20926463d41117017a (diff) |
Switching to setcookie for PHP >= 7.3
-rw-r--r-- | system/core/Input.php | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/system/core/Input.php b/system/core/Input.php index fbe9c59b0..451737167 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -365,11 +365,26 @@ class CI_Input { log_message('error', $name.' cookie sent with SameSite=None, but without Secure attribute.'); } - $cookie_header = 'Set-Cookie: '.$prefix.$name.'='.rawurlencode($value); - $cookie_header .= ($expire === 0 ? '' : '; expires='.gmdate('D, d-M-Y H:i:s T', $expire)); - $cookie_header .= '; path='.$path.($domain !== '' ? '; domain='.$domain : ''); - $cookie_header .= ($secure ? '; secure' : '').($httponly ? '; HttpOnly' : '').'; SameSite='.$samesite; - header($cookie_header); + if (is_php('7.3')) + { + $setcookie_options = array( + 'expires' => $expire, + 'path' => $path, + 'domain' => $domain, + 'secure' => $secure, + 'httponly' => $httponly, + 'samesite' => $samesite, + ); + setcookie($prefix.$name, $value, $setcookie_options); + } + else + { + $cookie_header = 'Set-Cookie: '.$prefix.$name.'='.rawurlencode($value); + $cookie_header .= ($expire === 0 ? '' : '; expires='.gmdate('D, d-M-Y H:i:s T', $expire)); + $cookie_header .= '; path='.$path.($domain !== '' ? '; domain='.$domain : ''); + $cookie_header .= ($secure ? '; secure' : '').($httponly ? '; HttpOnly' : '').'; SameSite='.$samesite; + header($cookie_header); + } } // -------------------------------------------------------------------- |