Last active
August 29, 2015 14:08
-
-
Save harikt/204f546786cb84dd3ce8 to your computer and use it in GitHub Desktop.
How to create remember me session cookie in Symfony2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
use Symfony\Component\HttpFoundation\Session\Session; | |
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; | |
use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag; | |
$options = array( | |
'cookie_lifetime' => 123456, | |
'cookie_httponly' => true, | |
); | |
$session = new Session(new NativeSessionStorage($options), new NamespacedAttributeBag()); | |
$session->start(); | |
if ($session->get('name')) { | |
echo " World ! " . $session->get('name') . " <br /> "; | |
echo " Hello " . $session->get('next'); | |
} else { | |
// set and get session attributes | |
$session->set('name', 'Drak'); | |
$session->set('another', 'Boom'); | |
$session->set('next', 'Next'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So session life time is for all the session names, not just for one session. I thought in ZF2 session they are only storing the session lifetime for specific session. But I am wrong.