Skip to content

Commit 4a19fda

Browse files
committed
docs: add user guide
1 parent 7e92bc4 commit 4a19fda

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

user_guide_src/source/changelogs/v4.2.7.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Release Date: Unreleased
1212
BREAKING
1313
********
1414

15+
- The default values of the parameters in :php:func:`set_cookie()` and :php:meth:`CodeIgniter\\HTTP\\Response::setCookie()` has been fixed. Now the default values of ``$secure`` and ``$httponly`` are ``null``, and these values will be replaced with the ``Config\Cookie`` values.
1516
- ``Time::__toString()`` is now locale-independent. It returns database-compatible strings like '2022-09-07 12:00:00' in any locale.
1617

1718
Enhancements

user_guide_src/source/helpers/cookie_helper.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ The following functions are available:
2929
:param string $domain: Cookie domain (usually: .yourdomain.com)
3030
:param string $path: Cookie path
3131
:param string $prefix: Cookie name prefix. If ``''``, the default from **app/Config/Cookie.php** is used
32-
:param bool $secure: Whether to only send the cookie through HTTPS
33-
:param bool $httpOnly: Whether to hide the cookie from JavaScript
32+
:param bool $secure: Whether to only send the cookie through HTTPS. If ``null``, the default from **app/Config/Cookie.php** is used
33+
:param bool $httpOnly: Whether to hide the cookie from JavaScript. If ``null``, the default from **app/Config/Cookie.php** is used
3434
:param string $sameSite: The value for the SameSite cookie parameter. If ``null``, the default from **app/Config/Cookie.php** is used
3535
:rtype: void
3636

37+
.. note:: Prior to v4.2.7, the default values of ``$secure`` and ``$httpOnly`` were ``false``
38+
due to a bug, and these values from **app/Config/Cookie.php** were never used.
39+
3740
This helper function gives you friendlier syntax to set browser
3841
cookies. Refer to the :doc:`Response Library </outgoing/response>` for
3942
a description of its use, as this function is an alias for

user_guide_src/source/installation/upgrade_427.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,43 @@ Please refer to the upgrade instructions corresponding to your installation meth
1515
Breaking Changes
1616
****************
1717

18+
set_cookie()
19+
============
20+
21+
Due to a bug, :php:func:`set_cookie()` and :php:meth:`CodeIgniter\\HTTP\\Response::setCookie()`
22+
in the previous versions did not use the ``$secure`` and ``$httponly`` values in ``Config\Cookie``.
23+
The following code did not issue a cookie with the secure flag even if you set ``$secure = true``
24+
in ``Config\Cookie``::
25+
26+
helper('cookie');
27+
28+
$cookie = [
29+
'name' => $name,
30+
'value' => $value,
31+
];
32+
set_cookie($cookie);
33+
// or
34+
$this->response->setCookie($cookie);
35+
36+
But now the values in ``Config\Cookie`` are used for the options that are not specified.
37+
The above code issues a cookie with the secure flag if you set ``$secure = true``
38+
in ``Config\Cookie``.
39+
40+
If your code depends on this bug, please change it to explicitly specify the necessary options::
41+
42+
$cookie = [
43+
'name' => $name,
44+
'value' => $value,
45+
'secure' => false, // Set explicitly
46+
'httponly' => false, // Set explicitly
47+
];
48+
set_cookie($cookie);
49+
// or
50+
$this->response->setCookie($cookie);
51+
52+
Others
53+
======
54+
1855
- ``Time::__toString()`` is now locale-independent. It returns database-compatible strings like '2022-09-07 12:00:00' in any locale. Most locales are not affected by this change. But in a few locales like `ar`, `fa`, ``Time::__toString()`` (or ``(string) $time`` or implicit casting to a string) no longer returns a localized datetime string. if you want to get a localized datetime string, use :ref:`Time::toDateTimeString() <time-todatetimestring>` instead.
1956

2057
Project Files

user_guide_src/source/outgoing/response.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,14 @@ The methods provided by the parent class that are available are:
370370
:param string $domain: Cookie domain
371371
:param string $path: Cookie path
372372
:param string $prefix: Cookie name prefix. If set to ``''``, the default value from **app/Config/Cookie.php** will be used
373-
:param bool $secure: Whether to only transfer the cookie through HTTPS
374-
:param bool $httponly: Whether to only make the cookie accessible for HTTP requests (no JavaScript)
373+
:param bool $secure: Whether to only transfer the cookie through HTTPS. If set to ``null``, the default value from **app/Config/Cookie.php** will be used
374+
:param bool $httponly: Whether to only make the cookie accessible for HTTP requests (no JavaScript). If set to ``null``, the default value from **app/Config/Cookie.php** will be used
375375
:param string $samesite: The value for the SameSite cookie parameter. If set to ``''``, no SameSite attribute will be set on the cookie. If set to ``null``, the default value from **app/Config/Cookie.php** will be used
376376
:rtype: void
377377

378+
.. note:: Prior to v4.2.7, the default values of ``$secure`` and ``$httponly`` were ``false``
379+
due to a bug, and these values from **app/Config/Cookie.php** were never used.
380+
378381
Sets a cookie containing the values you specify. There are two ways to
379382
pass information to this method so that a cookie can be set: Array
380383
Method, and Discrete Parameters:

0 commit comments

Comments
 (0)