phptwigcraftcms

How I can access to $_SESSION in Craft CMS 3.x


Is it possible to access to $_SESSION variable in .twig template Craft CMS 3.x version ? I found articles about 2.5 version but nothing for 3.x+.

Thanks for help.


Solution

  • The session component in Craft 3 is available under Craft::$app->session in PHP and craft.app.session in twig. This returns a craft\web\Session object corresponding to the current user's session.