PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 28, 2021

[FIXED] Symfony 6 RequestStack Session not getting value

 December 28, 2021     symfony     No comments   

Issue

Until now I worked with Symfony 5.2. Now I installed new environment with Symfony 6.

Now the Session engine is changed, RequestStack should use now. I setup as https://symfony.com/doc/current/session.html.

It looks like, value is saving but not loading again (session folder contains corresponding files).

Initial route:

/**
 * @Route(
 *     "/",
 *     name="home",
 *     methods={"GET","POST"}
 * )
 *
 * @param RequestStack $requestStack
 * @return Response
 */
public function index(RequestStack $requestStack): Response
{
    $session = $requestStack->getSession();
    $session->set('test','test');

    return $this->render('main/index.html.twig', []);
}

Test route:

    /**
 * @Route(
 *     "/test",
 *     name="test",
 *     methods={"GET","POST"}
 * )
 * @param RequestStack $requestStack
 * @return Response
 * @throws Exception
 */
public function test(RequestStack $requestStack): Response
{
    $session = $requestStack->getSession();
    echo "Test: ".$session->get('test','err');  // <== I get 'err'

    return $this->render('main/index.html.twig', []);
}
  • Every main page refresh, new session file will created.
  • In browser i don't see corresponding session hash
  • In JavaScript document.cookie = "MyCookie"; works

Solution

I found the problem: Since update Synfony and PHP, access to resources by domain name needs to have certificate. After installing lets encrypt it works (also for in-house-acces-only).



Answered By - Adi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing