如何在joomla 3.2中获取用户名 [英] How to get username in joomla 3.2

查看:113
本文介绍了如何在joomla 3.2中获取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个外部应用程序,用于检索Joomla用户信息,并且使用以下代码:

I had built an external application which retrieve Joomla User Information and I user the code as below :

session_start();
define( '_JEXEC', 1 );
define('JPATH_BASE', '../' );
require_once ( JPATH_BASE .'../includes/defines.php' );
require_once ( JPATH_BASE .'../includes/framework.php' );
$app = JFactory::getApplication('site');
$user = JFactory::getUser();
$myuserid = $user->username;
$_SESSION["myid"] = "$myuserid";
$myid = $_SESSION["myid"];
echo 'User name: ' . $myid . '<br />';

但是,$ myid的输出未显示在站点中.它只是显示为:

However, the output of $myid is not displayed in the site. It just displayed as :

User name :

显示的应该是:

User name : admin

我的编码有问题吗? 任何帮助将不胜感激.

Is there's a problem with my coding? Any help will be appreciated.

推荐答案

尝试一下,

我认为该框架无法在外部页面上正确加载.

I think the framework not loaded correctly on the external page.

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$user = JFactory::getUser();
echo '<pre/>';
print_r($user);

请勿将session_start()用于Joomla如果需要使用会话,请尝试使用Joomla会话库.

Do not use session_start() for Joomla If you need to use session try Joomla session library.

$session = JFactory::getSession();
$session->set('variable','your_value');
echo $session->get('variable');

在您的情况下,登录的管理员名称将为

In your case the logged in admin name will be.

echo $user->username;

希望它能起作用.

这篇关于如何在joomla 3.2中获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆