Get User Id from Session in Joomla

If you want to get user details from session in internal php page of joomla then you can use following code:

<?php
$user =& JFactory::getUser();
$username=$user->get('username'); // username text same as database table
$userId = $user->get( 'id' );  //id text same as database table
$useremail=$user->get('email'); // email text same as database table
echo "UserID is:-".$userId;
echo '</br>';
echo "UserName is:-".$username;
echo '</br>';
echo "User Email is:-".$useremail;
?>

If you want to get user details from session in external php page of joomla then you can use following code:

<?php define( '_JEXEC', 1 ); 
define( 'DS', DIRECTORY_SEPARATOR ); 
define('JPATH_BASE', dirname(__FILE__) ); 
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(); 
$username=$user->get('username'); // username text same as database table
$userId = $user->get( 'id' );  //id text same as database table 
$useremail=$user->get('email'); // email text same as database table
echo "UserID is:-".$userId;
echo '</br>';
echo "UserName is:-".$username; 
echo '</br>'; 
echo "User Email is:-".$useremail; ?>
Advertisements
Categories: Joomla | Tags: , , , | Leave a comment

Post navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: