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 />';
我已在我的外部 php 文件中添加了此代码。$specificuser
代码正在运行;但有时会显示$user
输出,有时则不会。对这个问题有任何想法吗?输出在这里:
User name:
Real name:
Specific User name: user
Specific Real name: Super User