[TYPO3-english] Changing fe_users Session Data

Jigal van Hemert jigal.van.hemert at typo3.org
Mon Nov 16 16:02:36 CET 2015


Hi,

On 16/11/2015 13:07, Christian Platt wrote:
> After Login, is there the possibility to change a value in fe_users session, so that the value is always accessible via
>
> $GLOBALS["TSFE"]->fe_user->user
>
> in the same session without writing it to harddisk?

Why specifically *without writing it to harddisk*? Webservers are 
stateless, so on each request everything needs to be built from scratch. 
If there is a cookie that indicates that the FE user is logged in, the 
FE user data is fetched from the database.
Therefore you need to store it somewhere to be able to retrieve it later.

> $GLOBALS["TSFE"]->fe_user->setKey("user“,"akey", $keyValue);
>
> This can be found in $GLOBALS["TSFE"]->fe_user->uc;
>
> and aftter writeUC() it is stored in
>
>   $GLOBALS["TSFE"]->fe_user->uc as json…

You can use the proper API to store it:

$GLOBALS['TSFE']->fe_user->setKey('user', 'your_key', $value);
$GLOBALS['TSFE']->fe_user->storeSessionData();

and retrieve it with:

$value = $GLOBALS['TSFE']->fe_user->getKey('user', 'your_key');

> But that is not, what i like.
>
> I would like to have set a property to the user
>
> $GLOBALS["TSFE"]->fe_user->user[’special’]=‚Foo‘ which is initially empty or 0.

That would imply that you extend the FE users table with a new property.

> which i can access on another page  by using
>
> $GLOBALS["TSFE"]->fe_user->user[’special’] to use it.

You could extend the FE users table, but if you want to set it on page 
'A' and read it on page 'B' then the value needs to be stored ("writing 
it on harddisk").

-- 
Jigal van Hemert
TYPO3 CMS Active Contributor

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the TYPO3-english mailing list