[英]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 />';
我已將此代碼添加到我的外部php文件中。 $specificuser
代碼正在運行; 但是有時顯示$user
輸出,有時沒有顯示。 有什么問題的想法嗎? 輸出在這里:
User name:
Real name:
Specific User name: user
Specific Real name: Super User
JFactory::getUser()
方法加載當前用戶對象:
當您登錄時,第二種情況也適用,但是會話期滿。
您不啟動Joomla! 應用程序,因此會話處理等不起作用。
有關如何初始化Joomla的工作示例,請參見我對類似問題的回答 ! 正確地。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.