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'); | |
} |
Is there a way to set the session for only certain variable to have long cookie life time, and others with shorter life time when browser close ?
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In ZF2 it can be done to save the session of a container https://gist.github.com/harikt/41028e9489396b066df2 . So in this case I don't need all the names to get saved for 2 or what ever day, but only some special variables. Thank you.