I would like to create a secure PHP session in Symfony 4
I looked for informations in the Symfony docs and API documentation but could not find any reference to my problem.
In plain PHP I used to do the following to create a secure PHP session:
$session_name = 'session';
$secure = true;
$httponly = true;
$cookieParams = session_get_cookie_params();
session_set_cookie_params(
$cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
$secure,
$httponly
);
session_name($session_name);
session_start();
How do you do something similar in Symfony 4 ? the following code does not work:
$session->set('lifetime', 0);
$session->set('secure', true);
$session->set('httponly', true);
As pointed by sam and with the correct documentation
In the Symfony framework, these options should be set in the framework.yaml
session:
handler_id: ~
cookie_secure: true
cookie_httponly: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With