How to implement remember me programatically in symfony2? How to implement remember me programatically in symfony2? symfony symfony

How to implement remember me programatically in symfony2?


Try to use RememberMeToken

$key = $this->getParameter('secret'); // your security key from parameters.yml$token = new RememberMeToken($user, 'main', $key); $this->get('security.context')->setToken($token);


I had the same problem.you should use RememberMeToken instead of UsernamePasswordToken.

The class parameters are very similar to UsernamePasswordToken so I don't go into details.


You can create a cookie with an unique ID. Then store this cookie in a database and check this database whenever a new visitor visits the site. In case you have your users stored in a database it would be best to make an extra column to store this information. Have a look at FOSUserBundle by the way.