How to session in TYPO3 and access it globally.

In this blog, you will learn how to set session variable and how to manage it in TYPO3.
In TYPO3, you can create session variable, unset session variable and also can get value just by using $GlOBALS variable.

If you want to create session variable you can create as per below. Here I have set of values in $resultObj variable and I want to set it in session of TYPO3.
Here,
sess - define for session variable
customlogin - my variable to set session values, so that I can get all my values using that variable.
$resultObj - set of value that I am going to assign to my session variable.

Below is the simple code to set session values.

$resultObj = $result;
$GLOBALS['TSFE']->fe_user->setKey('ses', 'customlogin', $resultObj);

Below is the code to retrieve session data.

$userDetails = $GLOBALS['TSFE']->fe_user->sesData['customlogin'];

Below is the code to unset session values.

$GLOBALS['TSFE']->fe_user->setKey('ses', 'customlogin', NULL);

If you have any query, feel free to ask me. Keep reading .. Enjoy!

Post a Comment

Thanks for your comment.