Skip to content

Commit ca74b82

Browse files
authored
Merge pull request #6016 from kenjis/fix-docs-cookies
docs: improve cookies
2 parents 403a4c8 + 298643d commit ca74b82

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

user_guide_src/source/helpers/cookie_helper.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ The following functions are available:
3131
:param string $prefix: Cookie name prefix
3232
:param bool $secure: Whether to only send the cookie through HTTPS
3333
:param bool $httpOnly: Whether to hide the cookie from JavaScript
34-
:param string $sameSite: The value for the SameSite cookie parameter. If null, the default from `config/App.php` is used
34+
: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

3737
This helper function gives you friendlier syntax to set browser
3838
cookies. Refer to the :doc:`Response Library </outgoing/response>` for
3939
a description of its use, as this function is an alias for
40-
``Response::setCookie()``.
40+
:php:func:`Response::setCookie() <setCookie>`.
4141

4242
.. php:function:: get_cookie($index[, $xssClean = false])
4343
@@ -69,7 +69,13 @@ The following functions are available:
6969
.. literalinclude:: cookie_helper/002.php
7070

7171
This function is otherwise identical to ``set_cookie()``, except that it
72-
does not have the value and expiration parameters. You can submit an
72+
does not have the ``value`` and ``expire`` parameters.
73+
74+
.. note:: When you use ``set_cookie()``,
75+
if the ``value`` is set to empty string and the ``expire`` is set to ``0``, the cookie will be deleted.
76+
If the ``value`` is set to non-empty string and the ``expire`` is set to ``0``, the cookie will only last as long as the browser is open.
77+
78+
You can submit an
7379
array of values in the first parameter or you can set discrete
7480
parameters.
7581

user_guide_src/source/outgoing/response.rst

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ The methods provided by the parent class that are available are:
370370
:param string $prefix: Cookie name prefix
371371
:param bool $secure: Whether to only transfer the cookie through HTTPS
372372
:param bool $httponly: Whether to only make the cookie accessible for HTTP requests (no JavaScript)
373-
: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 `config/App.php` will be used
373+
: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
374374
:rtype: void
375375

376376
Sets a cookie containing the values you specify. There are two ways to
@@ -384,30 +384,31 @@ The methods provided by the parent class that are available are:
384384

385385
.. literalinclude:: response/023.php
386386

387-
**Notes**
388-
389-
Only the name and value are required. To delete a cookie set it with the
390-
expiration blank.
387+
Only the ``name`` and ``value`` are required. To delete a cookie set it with the
388+
``expire`` blank.
391389

392-
The expiration is set in **seconds**, which will be added to the current
390+
The ``expire`` is set in **seconds**, which will be added to the current
393391
time. Do not include the time, but rather only the number of seconds
394-
from *now* that you wish the cookie to be valid. If the expiration is
392+
from *now* that you wish the cookie to be valid. If the ``expire`` is
395393
set to zero the cookie will only last as long as the browser is open.
396394

395+
.. note:: But if the ``value`` is set to empty string and the ``expire`` is set to ``0``,
396+
the cookie will be deleted.
397+
397398
For site-wide cookies regardless of how your site is requested, add your
398-
URL to the **domain** starting with a period, like this:
399+
URL to the ``domain`` starting with a period, like this:
399400
.your-domain.com
400401

401-
The path is usually not needed since the method sets a root path.
402+
The ``path`` is usually not needed since the method sets a root path.
402403

403-
The prefix is only needed if you need to avoid name collisions with
404+
The ``prefix`` is only needed if you need to avoid name collisions with
404405
other identically named cookies for your server.
405406

406-
The secure flag is only needed if you want to make it a secure cookie
407+
The ``secure`` flag is only needed if you want to make it a secure cookie
407408
by setting it to ``true``.
408409

409-
The SameSite value controls how cookies are shared between domains and sub-domains.
410-
Allowed values are 'None', 'Lax', 'Strict' or a blank string ``''``.
410+
The ``samesite`` value controls how cookies are shared between domains and sub-domains.
411+
Allowed values are ``'None'``, ``'Lax'``, ``'Strict'`` or a blank string ``''``.
411412
If set to blank string, default SameSite attribute will be set.
412413

413414
**Discrete Parameters**
@@ -425,18 +426,16 @@ The methods provided by the parent class that are available are:
425426
:param string $prefix: Cookie name prefix
426427
:rtype: void
427428

428-
Delete an existing cookie by setting its expiry to ``0``.
429-
430-
**Notes**
429+
Delete an existing cookie.
431430

432-
Only the name is required.
431+
Only the ``name`` is required.
433432

434-
The prefix is only needed if you need to avoid name collisions with
433+
The ``prefix`` is only needed if you need to avoid name collisions with
435434
other identically named cookies for your server.
436435

437-
Provide a prefix if cookies should only be deleted for that subset.
438-
Provide a domain name if cookies should only be deleted for that domain.
439-
Provide a path name if cookies should only be deleted for that path.
436+
Provide a ``prefix`` if cookies should only be deleted for that subset.
437+
Provide a ``domain`` name if cookies should only be deleted for that domain.
438+
Provide a ``path`` name if cookies should only be deleted for that path.
440439

441440
If any of the optional parameters are empty, then the same-named
442441
cookie will be deleted across all that apply.
@@ -456,10 +455,10 @@ The methods provided by the parent class that are available are:
456455

457456
**Notes**
458457

459-
Only the name is required. If a prefix is specified, it will be prepended to the cookie name.
458+
Only the ``name`` is required. If a ``prefix`` is specified, it will be prepended to the cookie name.
460459

461-
If no value is given, the method just checks for the existence of the named cookie.
462-
If a value is given, then the method checks that the cookie exists, and that it
460+
If no ``value`` is given, the method just checks for the existence of the named cookie.
461+
If a ``value`` is given, then the method checks that the cookie exists, and that it
463462
has the prescribed value.
464463

465464
Example:
@@ -473,7 +472,7 @@ The methods provided by the parent class that are available are:
473472
:rtype: ``Cookie|Cookie[]|null``
474473

475474
Returns the named cookie, if found, or ``null``.
476-
If no name is given, returns the array of ``Cookie`` objects.
475+
If no ``name`` is given, returns the array of ``Cookie`` objects.
477476

478477
Example:
479478

0 commit comments

Comments
 (0)