0
votes

I recently upgraded my website to Joomla 3.

I have built an external application which retrieve Joomla User Information.

Below code worked perfectly for Joomla 2.5:

<?php
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', '../' );

//Including the defines.php and framework.php of Joomla 2.5 CMS
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries' .DS. 'joomla'. DS. 'user' .DS. 'authentication.php');
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

//Accessing the Users table in Joomla 2.5 CMS
$mainframe->route();
$user =& JFactory::getUser();
print($user);
?>

After the site upgrade, the above code does not work in Joomla 3.

First I found that DS has been depreciated in Joomla 3. Second I found that $mainframe has also been depreciated in Joomla 3.

So here is the updated codespec:

<?php
define( '_JEXEC', 1 );

if(!defined('DS'))
{
   define('DS',DIRECTORY_SEPARATOR);
}

define('JPATH_BASE', '../' );

//Including the defines.php and framework.php of Joomla 2.5 CMS
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries' .DS. 'joomla'. DS. 'user' .DS. 'authentication.php');
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );

$app = JFactory::getApplication();
$app->initialise();

//Accessing the Users table in Joomla 2.5 CMS
$app->route();
$user = JFactory::getUser();

print_r($user);
exit;

?>

Unfortunately the above codespec does not work, it gives me a blank page.

Any help will be appreciated.

2
which user are you trying to get though? getUser() gets the current user object. - Lodder
yes current user object... - mkb

2 Answers

3
votes

I've tested this myself using Joomla 3.2 and it works fine. This is all the code you need.

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

print_r ($user);

Hope this helps

0
votes

where you define 'JPATH_BASE' you need to remove the trailing / - or alternatively, removing prepending / from the file locations.