@@ -9,7 +9,7 @@ Configuration
9
9
10
10
Sessions are provided by the `HttpFoundation component `_, which is included in
11
11
all Symfony applications, no matter how you installed it. Before using the
12
- sessions, check their configuration:
12
+ sessions, check their default configuration:
13
13
14
14
.. configuration-block ::
15
15
@@ -20,12 +20,12 @@ sessions, check their configuration:
20
20
session :
21
21
# enables the support of sessions in the app
22
22
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 '
29
29
30
30
.. code-block :: xml
31
31
@@ -42,11 +42,13 @@ sessions, check their configuration:
42
42
<!--
43
43
enabled: enables the support of sessions in the app
44
44
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
46
47
-->
47
48
<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" />
50
52
</framework : config >
51
53
</container >
52
54
@@ -58,15 +60,69 @@ sessions, check their configuration:
58
60
// enables the support of sessions in the app
59
61
'enabled' => true,
60
62
// 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
+ // ...
61
118
'handler_id' => 'session.handler.native_file',
62
- // the directory where session metadata is stored
63
119
'save_path' => '%kernel.project_dir%/var/sessions/%kernel.environment%',
64
120
],
65
121
]);
66
122
67
123
Check out the Symfony config reference to learn more about the other available
68
124
: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,
70
126
check out this article: :doc: `/doctrine/pdo_session_storage `.
71
127
72
128
Basic Usage
0 commit comments