php 获取当前登录的 TYPO3 用户(fe-user)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10027970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get currently logged in TYPO3 User (fe-user)
提问by Halest
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.
我为我的网站编写了一个 DB-Communications-System,您可以在其中通过 Java 应用程序、Android 应用程序和网站本身为其他家庭留言。在此网站上,您通过 fe_user 登录掩码登录,然后您可以访问该表单。在这里,我有一个下拉选择“From”和一个下拉选择“For”,其中有可供选择的家庭名称。我想要的是页面读取当前登录的用户并根据该用户自动设置“发件人”变量。
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
strleng()始终为 0,print_r($_GLOBALS['TSFE'])始终为空
,整个 Array 也为空。
我究竟做错了什么?在访问这些变量之前,我必须做些什么吗?同样在某些情况下,它不识别这个对象,而不是解释变量,它只是说
"->fe_user->user"
on the website.
在网站上。
Thank you very much
非常感谢
回答by Cybot
print_r($_GLOBALS['TSFE']) is always empty
print_r($_GLOBALS['TSFE']) 总是空的
you should try $GLOBALS['TSFE']and not$_GLOBALS['TSFE']
你应该尝试$GLOBALS['TSFE']而不是$_GLOBALS['TSFE']
so $GLOBALS['TSFE']->fe_user->useris absolutely correct to check for a logged in user
所以$GLOBALS['TSFE']->fe_user->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.
附录 2019-08-15:根据您要实现的目标或您正在寻找的确切信息以及您使用的 TYPO3 版本,有不同的方法可以使用此变量。
For example to ensure the current user is authenticated with your TYPO3 you can retrieve his ID by
例如,为了确保当前用户通过您的 TYPO3 进行身份验证,您可以通过以下方式检索他的 ID
$GLOBALS['TSFE']->fe_user->user['uid'];
回答by azec-pdx
If you need to get logged in user from TypoScript (and perhaps replace marker) this snippet of TS can be useful:
如果您需要从 TypoScript 登录用户(并且可能替换标记),此 TS 片段可能很有用:
page.10.marks.UNAME = TEXT
page.10.marks.UNAME.data = TSFE:fe_user|user|username
回答by Mihir Bhatt
This will return id of current logged in user
这将返回当前登录用户的 id
$GLOBALS['TSFE']->fe_user->user['uid'];
回答by maholtz
Install extension kickstarterand create an frontend-plugin for your own. You will get a simple form example. There you can use $GLOBALS['TSFE'] etc. (Check "By default plugins are generated as cachable USER cObjects. Check this checkbox to generate an uncached USER_INT cObject." while creating your frontend plugin!)
安装扩展kickstarter并为您自己创建一个前端插件。您将获得一个简单的表单示例。在那里您可以使用 $GLOBALS['TSFE'] 等(检查“默认情况下插件生成为可缓存的 USER cObjects。选中此复选框以生成未缓存的 USER_INT cObject。”在创建前端插件时!)
It is the old-school way to start extensions, but i guess in your case the quickest and easiest way to solv your problem.
这是开始扩展的老式方法,但我想在您的情况下是解决问题的最快和最简单的方法。
回答by user3895544
@Halest and there's the sql injection vulnerability
@Halest 并且存在 sql 注入漏洞
$ergebnis = mysql_query("select ses_userid from fe_sessions WHERE ses_id='$SessionID'");
By the way, never trust cookies. They can be modified or even turned off. Try to use more $GLOBALS['DB'] to interact with the database.
顺便说一句,永远不要相信cookies。它们可以被修改甚至关闭。尝试使用更多的 $GLOBALS['DB'] 与数据库进行交互。
回答by Ashish v
$GLOBALS['TSFE']->fe_user->user
This will return all data of fe_user table. you can get whatever value you want.
这将返回 fe_user 表的所有数据。你可以得到任何你想要的价值。
回答by Hauke
if you need the logged user in t3:
如果您需要 t3 中的登录用户:
$user=null;
if($GLOBALS['TSFE']->loginUser){
$user=$GLOBALS['TSFE']->fe_user->user;
}

