Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8041641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:17:20+00:00 2026-06-05T04:17:20+00:00

Is there a way I can store when was the last time a user

  • 0

Is there a way I can store when was the last time a user logged in?

I’m using symfony2, and everything’s working alright with the security configuration.

I’ve seen this Security and login on a Symfony 2 based project, which is a similar question, but it just doesn’t fit my needs.

Is there any other solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:17:23+00:00Added an answer on June 5, 2026 at 4:17 am

    You can create an AuthenticationHandler that Symfony will call when user login successfully, you can save the login time into a User entity property (supposing that you have this scenario).

    First, create the success authentication handler:

    namespace Acme\TestBundle\Handler;
    
    use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
    use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\RedirectResponse;
    use Symfony\Component\DependencyInjection\ContainerAware;
    
    class AuthenticationHandler extends ContainerAware implements AuthenticationSuccessHandlerInterface
    {
        function onAuthenticationSuccess(Request $request, TokenInterface $token)
        {
            $token->getUser()->setLoginTime(new \DateTime());
            $this->container->get('doctrine')->getEntityManager()->flush();
    
            return new RedirectResponse($this->container->get('router')->generate('login_success'));
        }
    }
    

    Then you need to register the authentication handler as a service in a configuration file, for example, src/Acme/TestBundle/resources/Config/services.yml

    services:
        authentication_handler:
            class: Acme\TestBundle\Handler\AuthenticationHandler
            calls:
                - [ setContainer, [ @service_container ] ] 
    

    And configure the login form to use the created handler, check out your security.yml

    form_login:
        success_handler: authentication_handler
    

    Obviously, for this to work, you need to have a User entity with a loginTime property and the corresponding setter. And you need to configure the login to use the User entity repository as user provider and the DaoAuthenticationProvider, as explained here: http://symfony.com/doc/current/book/security.html#loading-users-from-the-database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can store a socket and a username in a
Is there way that I can read the file from remote server using fopen
I there any way I can create and post comments, without using comments plugin
Is there a way i can store a number locally? I want to make
Is there any way that I can list the pages which are currently stored
Is there any way can declare a bean in just like JSP UseBean in
Is there any way I can trigger omniauth callback manually? What I mean to
Is there any way I can validate a jsf input text that is readonly
Is there any way you can force Wi-Fi to stay active with lockscreen ?
I there any way I can get the the cost history or the values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.