获取Joomla用户ID返回空白页面

时间:2013-11-09 22:27:12

标签: php joomla

我在Joomla 2.5.16上,我想要当前的用户ID和组ID。

以下代码返回空白页面,为什么?

<?php

include_once $_SERVER['DOCUMENT_ROOT']."/includes/defines.php";
include_once $_SERVER['DOCUMENT_ROOT']."/includes/framework.php";

$user = JFactory::getUser();
$group_id = &JFactory::group_id();
$user_id = $user->get('id');

echo $user_id;
echo $group_id;


?>

1 个答案:

答案 0 :(得分:0)

试试这个

$user =& JFactory::getUser();

if (!$user->guest) {
  echo 'You are logged in as:<br />';
  echo 'User name: ' . $user->username . '<br />';
  echo 'Real name: ' . $user->name . '<br />';
  echo 'User ID  : ' . $user->id . '<br />';
}