Get currently logged in TYPO3 User (fe-user)

Halest picture Halest · Apr 5, 2012 · Viewed 28.7k times · Source

I'm usually not someone who posts in a forum, since I was always able to find something without bothering anyone. Anyway, this time I had no luck.

I have programmed a DB-Communications-System for my website, where you can leave messages for the rest of the family from a Java application, an Android app and the website itself. On this website you login through a fe_user login mask and then you can access the form. Here I have a dropdown selection 'From' and a dropdown selection 'For' where there are the names of the family to choose. What I want is for the page to read the currently logged in user and automatically set the 'From' Variable according to this user.

On many pages I have found

$GLOBALS['TSFE']->fe_user->user 

and the accordig variations of it, but no matter how I tried to get something out of it,

strleng() is always 0,
print_r($_GLOBALS['TSFE']) is always empty
and the whole Array is also empty.
What am I doing wrong? Do I have to do something before I can access these variables? Also in some cases, it doesn´t recognize this object and instead of interpreting the variable, it just says

"->fe_user->user"

on the website.

Thank you very much

Answer

Cybot picture Cybot · Oct 23, 2012

print_r($_GLOBALS['TSFE']) is always empty

you should try $GLOBALS['TSFE'] and not $_GLOBALS['TSFE']

so $GLOBALS['TSFE']->fe_user->user is absolutely correct to check for a logged in user


Addendum 2019-08-15: Depending on what your are trying to achieve or what exact information you are looking for and what version of TYPO3 your are using there are different ways to use this variable.

For example to ensure the current user is authenticated with your TYPO3 you can retrieve his ID by

$GLOBALS['TSFE']->fe_user->user['uid'];