[英]joomla external php code for login user data
define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
require_once ( JPATH_BASE .'/libraries/joomla/factory.php' );
$user = JFactory::getUser();
echo 'User name: ' . $user->username . '<br />';
echo 'Real name: ' . $user->name . '<br />';
$specificuser = JFactory::getUser(42);
echo 'Specific User name: ' . $specificuser->username . '<br />';
echo 'Specific Real name: ' . $specificuser->name . '<br />';
I have added this code in my external php file. 我已将此代码添加到我的外部php文件中。 The
$specificuser
code is working; $specificuser
代码正在运行; but sometimes the $user
output is shown, sometimes it isn't. 但是有时显示
$user
输出,有时没有显示。 Any idea of the problem? 有什么问题的想法吗? output is here:
输出在这里:
User name:
Real name:
Specific User name: user
Specific Real name: Super User
JFactory::getUser()
method loads current user object: JFactory::getUser()
方法加载当前用户对象:
Second case also applies when you log in, but your session expires. 当您登录时,第二种情况也适用,但是会话期满。
You don't start the Joomla! 您不启动Joomla! application, so session handling and other things do not work.
应用程序,因此会话处理等不起作用。
See my answer to a similar question for a working example on how to initialize Joomla! 有关如何初始化Joomla的工作示例,请参见我对类似问题的回答 ! correctly.
正确地。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.