Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get currently logged in TYPO3 User (fe-user)

Tags:

html

php

typo3

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

like image 429
Halest Avatar asked Apr 05 '12 11:04

Halest


3 Answers

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'];
like image 160
Cybot Avatar answered Oct 31 '22 11:10

Cybot


If you need to get logged in user from TypoScript (and perhaps replace marker) this snippet of TS can be useful:

page.10.marks.UNAME = TEXT
page.10.marks.UNAME.data = TSFE:fe_user|user|username
like image 35
azec-pdx Avatar answered Oct 31 '22 10:10

azec-pdx


This will return id of current logged in user

$GLOBALS['TSFE']->fe_user->user['uid'];
like image 5
Mihir Bhatt Avatar answered Oct 31 '22 11:10

Mihir Bhatt