@@ -9,7 +9,7 @@ Configuration
99
1010Sessions are provided by the `HttpFoundation component `_, which is included in
1111all Symfony applications, no matter how you installed it. Before using the
12- sessions, check their configuration:
12+ sessions, check their default configuration:
1313
1414.. configuration-block ::
1515
@@ -20,12 +20,12 @@ sessions, check their configuration:
2020 session :
2121 # enables the support of sessions in the app
2222 enabled : true
23-
24- # ID of the service used for session storage
25- handler_id : session.handler.native_file
26-
27- # the directory where session metadata is stored
28- save_path : ' %kernel.project_dir%/var/sessions/%kernel.environment% '
23+ # ID of the service used for session storage.
24+ # NULL = means that PHP's default session mechanism is used
25+ handler_id : null
26+ # improves the security of the cookies used for sessions
27+ cookie_secure : ' auto '
28+ cookie_samesite : ' lax '
2929
3030 .. code-block :: xml
3131
@@ -42,11 +42,13 @@ sessions, check their configuration:
4242 <!--
4343 enabled: enables the support of sessions in the app
4444 handler-id: ID of the service used for session storage
45- save_path: the directory where session metadata is stored
45+ NULL means that PHP's default session mechanism is used
46+ cookie-secure and cookie-samesite: improves the security of the cookies used for sessions
4647 -->
4748 <framework : session enabled =" true"
48- handler-id =" session.handler.native_file"
49- save-path =" %kernel.project_dir%/var/sessions/%kernel.environment%" />
49+ handler-id =" null"
50+ cookie-secure =" auto"
51+ cookie-samesite =" lax" />
5052 </framework : config >
5153 </container >
5254
@@ -58,15 +60,69 @@ sessions, check their configuration:
5860 // enables the support of sessions in the app
5961 'enabled' => true,
6062 // ID of the service used for session storage
63+ // NULL means that PHP's default session mechanism is used
64+ 'handler_id' => null,
65+ // improves the security of the cookies used for sessions
66+ 'cookie_secure' => 'auto',
67+ 'cookie_samesite' => 'lax',
68+ ],
69+ ]);
70+
71+ Setting the ``handler_id `` config option to ``null `` means that Symfony will
72+ use the native PHP session mechanism. The session metadata files will be stored
73+ outside of the Symfony application, in a directory controlled by PHP. Although
74+ this usually simplify things, some session expiration related options may no
75+ work as expected if other applications that write to the same directory have
76+ short max lifetime settings.
77+
78+ If you prefer, you can use the ``session.handler.native_file `` service as
79+ ``handler_id `` to let Symfony manage the sessions itself. Another useful option
80+ is ``save_path ``, which defines the directory where Symfony will store the
81+ session metadata files:
82+
83+ .. configuration-block ::
84+
85+ .. code-block :: yaml
86+
87+ # config/packages/framework.yaml
88+ framework :
89+ session :
90+ # ...
91+ handler_id : ' session.handler.native_file'
92+ save_path : ' %kernel.project_dir%/var/sessions/%kernel.environment%'
93+
94+ .. code-block :: xml
95+
96+ <!-- config/packages/framework.xml -->
97+ <?xml version =" 1.0" encoding =" UTF-8" ?>
98+ <container xmlns =" http://symfony.com/schema/dic/services"
99+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
100+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
101+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
102+ http://symfony.com/schema/dic/services/services-1.0.xsd
103+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
104+
105+ <framework : config >
106+ <framework : session enabled =" true"
107+ handler-id =" session.handler.native_file"
108+ save-path =" %kernel.project_dir%/var/sessions/%kernel.environment%" />
109+ </framework : config >
110+ </container >
111+
112+ .. code-block :: php
113+
114+ // config/packages/framework.php
115+ $container->loadFromExtension('framework', [
116+ 'session' => [
117+ // ...
61118 'handler_id' => 'session.handler.native_file',
62- // the directory where session metadata is stored
63119 'save_path' => '%kernel.project_dir%/var/sessions/%kernel.environment%',
64120 ],
65121 ]);
66122
67123 Check out the Symfony config reference to learn more about the other available
68124:ref: `Session configuration options <config-framework-session >`. Also, if you
69- prefer to store session metadata in the database instead of the filesystem,
125+ prefer to store session metadata in a database instead of the filesystem,
70126check out this article: :doc: `/doctrine/pdo_session_storage `.
71127
72128Basic Usage
0 commit comments