简体   繁体   English

获取当前登录的 TYPO3 用户(fe-user)

[英]Get currently logged in TYPO3 User (fe-user)

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.我为我的网站编写了一个 DB-Communications-System,您可以在其中通过 Java 应用程序、Android 应用程序和网站本身为 rest 的家人留言。 On this website you login through a fe_user login mask and then you can access the form.在这个网站上,您通过 fe_user 登录掩码登录,然后您可以访问该表单。 Here I have a dropdown selection 'From' and a dropdown selection 'For' where there are the names of the family to choose.在这里,我有一个下拉选项“From”和一个下拉选项“For”,其中有可供选择的家庭名称。 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, strleng()始终为 0,
print_r($_GLOBALS['TSFE']) is always empty print_r($_GLOBALS['TSFE'])总是空的
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同样在某些情况下,它不识别这个 object 而不是解释变量,它只是说

"->fe_user->user"

on the website.在网站上。

Thank you very much非常感谢你

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->user is 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'];

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

This will return id of current logged in user这将返回当前登录用户的 ID

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

Install extension kickstarter and create an frontend-plugin for your own.安装扩展kickstarter并为您自己创建一个前端插件。 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!)在那里你可以使用 $GLOBALS['TSFE'] 等。

It is the old-school way to start extensions, but i guess in your case the quickest and easiest way to solv your problem.这是开始扩展的老式方法,但我想在您的情况下,这是解决问题的最快和最简单的方法。

@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.顺便说一下,永远不要相信 cookies。它们可以被修改甚至关闭。 Try to use more $GLOBALS['DB'] to interact with the database.尝试使用更多的 $GLOBALS['DB'] 来与数据库进行交互。

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

This will return all data of fe_user table.这将返回 fe_user 表的所有数据。 you can get whatever value you want.你可以得到任何你想要的价值。

if you need the logged user in t3:如果您需要 t3 中的登录用户:

$user=null;

if($GLOBALS['TSFE']->loginUser){
 $user=$GLOBALS['TSFE']->fe_user->user;
}

You can use the extension powermail to create your form and to save the data to an database table (afaik, the table needs to has at least fields uid and pid).您可以使用扩展名powermail来创建表单并将数据保存到数据库表中(afaik,该表需要至少有字段 uid 和 pid)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM