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

  • Home
  • SEARCH
  • 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 8710967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:45:42+00:00 2026-06-13T04:45:42+00:00

I read here how to check the login status of a user by inside

  • 0

I read here how to check the login status of a user by inside a twig template for a Symfony2-based website.
However, I need to know how to check if the user is logged in from inside a controller. I was quite sure the the following code was right:

$user = $this->get('security.context')->getToken()->getUser();

but it always return something, e.g. a logged user or an anonymous user.

Any idea?

  • 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-13T04:45:43+00:00Added an answer on June 13, 2026 at 4:45 am

    Warning: Checking for 'IS_AUTHENTICATED_FULLY' alone will return false if the user has logged in using “Remember me” functionality.

    According to Symfony 2 documentation, there are 3 possibilities:

    IS_AUTHENTICATED_ANONYMOUSLY – automatically assigned to a user who is
    in a firewall protected part of the site but who has not actually
    logged in. This is only possible if anonymous access has been allowed.

    IS_AUTHENTICATED_REMEMBERED – automatically assigned to a user who was
    authenticated via a remember me cookie.

    IS_AUTHENTICATED_FULLY – automatically assigned to a user that has
    provided their login details during the current session.

    Those roles represent three levels of authentication:

    If you have the IS_AUTHENTICATED_REMEMBERED role, then you also have
    the IS_AUTHENTICATED_ANONYMOUSLY role. If you have the
    IS_AUTHENTICATED_FULLY role, then you also have the other two roles.
    In other words, these roles represent three levels of increasing
    “strength” of authentication.

    I ran into an issue where users of our system that had used “Remember Me” functionality were being treated as if they had not logged in at all on pages that only checked for 'IS_AUTHENTICATED_FULLY'.

    The answer then is to require them to re-login if they are not authenticated fully, or to check for the remembered role:

    $securityContext = $this->container->get('security.authorization_checker');
    if ($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
        // authenticated REMEMBERED, FULLY will imply REMEMBERED (NON anonymous)
    }
    

    Hopefully, this will save someone out there from making the same mistake I made. I used this very post as a reference when looking up how to check if someone was logged in or not on Symfony 2.

    Source: http://symfony.com/doc/2.3/cookbook/security/remember_me.html#forcing-the-user-to-re-authenticate-before-accessing-certain-resources

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

Sidebar

Related Questions

I read here about std::auto_ptr<>::operator= Notice however that the left-hand side object is not
On my login activity, I check if the user has activated/ turned on their
I've read here that editing a file in-place is not possible since it's OS
As I read here , the VMT also contains a number of magic fields
I have read here http://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/ about how you probably shouldn't be trying to un-flatten
SO I read here In Entity Framework, getting the value of an identity column
Possible Duplicate: Search-like highlighting in NSTextView I thought i read here months ago that
I'm trying to set my entirely table row as an anchor. I've read here
I have an XML file that I'm trying to read from here , and
I've read the documentation here . I have an action, cook, which is applied

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.