繁体   English   中英

如何在joomla 3.2中获取用户名

[英]How to get username in joomla 3.2

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

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的输出未显示在站点中。 它只是显示为:

User name :

显示的应该是:

User name : admin

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

尝试这个,

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

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);

不要为Joomla使用session_start()如果需要使用会话,请尝试使用Joomla会话库。

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

您的情况是登录的管理员名称。

echo $user->username;

希望它能工作..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM