从Joomla菜单调用的php页面无法捕获登录的用户信息

时间:2013-03-13 07:54:43

标签: joomla

我们在Joomla中运行了一个应用程序。有一个菜单选项说“我的数据” - 点击它会在iframe中打开一个php页面。在这个目标php中,我们希望捕获当前登录的用户详细信息,我们将面临问题。

我们使用了JFactory::getUser(),但它没有显示任何内容。虽然如果任何特定的id作为参数传递给getuser,那么id的详细信息即将到来。 PFB代码。有人可以帮助我们。提前谢谢。

/*******Start of code*********/

define('_JEXEC', 1);

define('DS', DIRECTORY_SEPARATOR);

if (file_exists(dirname(__FILE__) . '/defines.php')) {

    include_once dirname(__FILE__) . '/defines.php';
}

if (!defined('_JDEFINES')) {

    define('JPATH_BASE', dirname(__FILE__));

    require_once JPATH_BASE.'/includes/defines.php';

}

require_once JPATH_BASE.'/includes/framework.php';

$app = JFactory::getApplication('site');

$app->initialise();

$user =& JFactory::getUser();

echo 'User name: ' . $user->username . '<br />'; echo 'Real name: ' . $user->name . '<br />';

$specificuser =& JFactory::getUser(403);

echo 'Specific User name: ' . $specificuser->username . '<br />'; echo 'Specific Real name: ' . $specificuser->name . '<br />';

/******eof code********/

2 个答案:

答案 0 :(得分:1)

而不是重新加载Joomla框架的方法,你可以只检查会话对象,这是Joomla在调试模式下的转储:

Session
__default
    session.counter ⇒ 13
    session.timer.start ⇒ 1363124213
    session.timer.last ⇒ 1363162265
    session.timer.now ⇒ 1363162286
    session.client.browser ⇒ Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0
    registry ⇒ {}
        user
            id ⇒ 0
            name ⇒
            username ⇒ 

答案 1 :(得分:1)

尝试使用以下内容:

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' );
$mainframe = JFactory::getApplication('site');

$user = JFactory::getUser();

echo 'User name: ' . $user->username . '<br />'; 
echo 'Real name: ' . $user->name . '<br />';

$specificuser = JFactory::getUser(403);

echo 'Specific User name: ' . $specificuser->username . '<br />'; 
echo 'Specific Real name: ' . $specificuser->name . '<br />';

希望这有帮助