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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:25:59+00:00 2026-06-08T20:25:59+00:00

If a user gets logged out (due to session expiration or for other reasons)

  • 0

If a user gets logged out (due to session expiration or for other reasons) in the background while using my Symfony2 application, I have implemented a JS layer appearing on the screen, allowing the user to log back in immediately and continue using the website.

The problem is, if the user is in the middle of filling a form and gets logged out, after logging back in using the JS layer, he’s still looking at the same form with values he already managed to type in, but his session changes. The CSRF token in the form is therefore invalid.

Is there a way to generate a new CSRF token based on the current session and particular form, grab it by AJAX and replace in the form? Or maybe there is other solution to this?

I don’t want to disable the CSRF protection.

  • 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-08T20:26:01+00:00Added an answer on June 8, 2026 at 8:26 pm

    Assuming that you use default CSRF Provider, in your AJAX controller you can get your CSRF Provider service and “ask” it to regenerate token:

    Symfony 2.3 (and prior)

    /** @var \Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider $csrf */
    $csrf = $this->get('form.csrf_provider');
    $token = $csrf->generateCsrfToken($intention); 
    
    return new Response($token);
    

    Symfony 2.4

    /** @var \Symfony\Component\Security\Csrf\CsrfTokenManagerInterface $csrf */
    $csrf = $this->get('security.csrf.token_manager');
    $token = $csrf->refreshToken($intention);
    
    return new Response($token);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
i have an web application in Cakephp. Application session gets destroyed and user gets
When a user gets to this screen, there is no way to cancel out
I have a page where the user gets directed to if they want to
So basically, I have a bunch of TextBoxes that the user gets to fill
I have a user who randomly gets a Script Error box (shown below) which
I'm using facebooker2 with my site unfortunately even if i logged out of facebook.com
I have a problem that when a user times out on my site they
Basically I keep getting thrown out from my asp.net mvc application because the User.Identity.IsAuthenticated
I have an intentservice that gets qued by the user and by my app

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.