简体   繁体   中英

Get Joomla user id returning blank page

I'm on Joomla 2.5.16 and I want the current user id and group id.

The following code is returning a blank page, why?

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


?>

try this

$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 />';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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