Stella inattivaStella inattivaStella inattivaStella inattivaStella inattiva

The following code is useful if you need to know if the current user is logged on Joomla CMS. 


The code will print something like the following output

Your name is Quake3 Spirit, your email is spirit AT, and your username is Spirit. Your user group is Super Users


You need to set your Joomla Path. In the script was set as "/site"


// Mandatory stuff for Joomla...pls customize your joomla path... /site
define( '_JEXEC', 1 );
define('JPATH_BASE',$_SERVER['DOCUMENT_ROOT']. "/site");
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
// Define object for my class joomlaSession
$oJoomla= new joomlaSession();
if ($oJoomla->isLogged()){		
	echo "<p>Your name is {$oJoomla->name}, your email is {$oJoomla->email}, and your username is {$oJoomla->username}. Your user group is  {$oJoomla->usergroup}</p>";
	} else {
	echo "<p>You are not authorized!</p>";
return "";
// Get var user from Joomla Objects
class joomlaSession {
        // variable
		public $db;
        public $user;
		public $name;
		public $username;
		public $email;
		public $usergroup;
		public function __construct() {
			$mainframe = JFactory::getApplication('site');
			$this->user  = JFactory::getUser();
			// get user group
        // methods
        public function isLogged() {
			if ($user->guest) {
				return false;
			} else {
				return true;
		public function getUserGroup(){
			// Get user group
			foreach($this->user->groups as $group){
				$query  = 'SELECT title FROM #__usergroups';
				$query .= ' WHERE id = ' . $group;
				$this->db->setQuery( $query );
				return $this->db->loadResult();


- have fun -

DISQUS - Leave your comments here