File tree Expand file tree Collapse file tree
user_guide_src/source/libraries Expand file tree Collapse file tree Original file line number Diff line number Diff 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**********************
135150Using the Cookie Store
136151**********************
Original file line number Diff line number Diff line change 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 );
Original file line number Diff line number Diff line change 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 );
You can’t perform that action at this time.
0 commit comments