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 8955505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:34:31+00:00 2026-06-15T14:34:31+00:00

I have this website with a login form and after I successfully logged in,

  • 0

I have this website with a login form and after I successfully logged in, I am redirected to the index. But when I click the back button, it lets me still view the login form which is not good. I want only the login form to be accessible by anonymous viewers only and not users who have logged in already. Is there a simple way to do this in symfony2? thanks

Here is my security.:


    jms_security_extra:
    secure_all_services: false
    expressions: true

security:
    encoders:
        Mata\UserBundle\Entity\User: 
            algorithm:        sha1
            encode_as_base64: false
            iterations:   1

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]


    providers:
        user_db:
            entity: { class: MataUserBundle:User,  property: username }

    firewalls:

        secured_area:
            pattern:    ^/
            anonymous: ~
            form_login:
                check_path: /login_check
                login_path: /login
            logout:
                path:   /logout
                target: /

    access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/, roles: ROLE_USER }
  • 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-15T14:34:33+00:00Added an answer on June 15, 2026 at 2:34 pm

    This may not be the best or proper way to do it, but its been the only way I could figure it out.

    In my loginAction method I do this (see the $secured variable). If the user session is authenticated then I redirect them to the home/index page. I don’t know of a way to do it via the firewall config because I don’t believe the login page would ever have a firewall attached to it.

    /**
     * @Route("/login", name="login")
     * @Template()
     */
    public function loginAction()
    {
        $request = $this->getRequest();
        $session = $request->getSession();
    
        // if the session is secured (user is logged in) 
        // then $secured will be an object with various user information.
        $secured = unserialize($session->get('_security_secured'));
        if ($secured) {
            return $this->redirect($this->generateUrl('home'));
        }
    
        // get the login error if there is one
        if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
        }
    
        return array(
            'last_username' => $session->get(SecurityContext::LAST_USERNAME),
            'error'         => $error,
            'embed'         => $request->isXmlHttpRequest()
        );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login form for my website. This login form have two text
I have this website http://wedessertmore.com that has some forms popup when you click on
I have this website (C#/ASP.NET) with a form where the user can register for
i have a website that has a simple login form. the form posts to
I have a website where we use Javascript to submit the login form. On
I want to put a login form everywhere on my website, after following a
So lets say I have some forms like this: Form A: <form name=formA> <input
So there is this website that has a login form. I want to log
I have a login form in a website which I have created.I have used
I have this website iloveforwards.com created using drupal. I would like to have a

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.