Skip to content

Commit dc8ab1d

Browse files
committed
docs: add "Sending Cookies"
1 parent 0fce046 commit dc8ab1d

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

user_guide_src/source/libraries/cookies.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ also take advantage of the class's constants to make it not a hassle.
131131

132132
.. literalinclude:: cookies/006.php
133133

134+
***************
135+
Sending Cookies
136+
***************
137+
138+
Set the ``Cookie`` objects in the ``CookieStore`` of the Response object, and
139+
the framework will automatically send the cookies.
140+
141+
Use :php:meth:`CodeIgniter\\HTTP\\Response::setCookie()` to set:
142+
143+
.. literalinclude:: cookies/017.php
144+
145+
You can also use the :php:func:`set_cookie()` helper function:
146+
147+
.. literalinclude:: cookies/018.php
148+
134149
**********************
135150
Using the Cookie Store
136151
**********************
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use CodeIgniter\Cookie\Cookie;
4+
use Config\Services;
5+
use DateTime;
6+
7+
$response = Services::response();
8+
9+
$cookie = new Cookie(
10+
'remember_token',
11+
'f699c7fd18a8e082d0228932f3acd40e1ef5ef92efcedda32842a211d62f0aa6',
12+
[
13+
'expires' => new DateTime('+2 hours'),
14+
]
15+
);
16+
17+
$response->setCookie($cookie);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use CodeIgniter\Cookie\Cookie;
4+
use DateTime;
5+
6+
helper('cookie');
7+
8+
$cookie = new Cookie(
9+
'remember_token',
10+
'f699c7fd18a8e082d0228932f3acd40e1ef5ef92efcedda32842a211d62f0aa6',
11+
[
12+
'expires' => new DateTime('+2 hours'),
13+
]
14+
);
15+
16+
set_cookie($cookie);

0 commit comments

Comments
 (0)