Take the 2-minute tour ×
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It's 100% free, no registration required.

I guess its going to be complicated but i will try my best to make you understand, what i want to achieve. All i want, is to make a custom HTML page, which will show the information of the user who has logged into my Joomla website. But i want it to be good looking, i want to have a background image, i want to include CSS & different fonts for different Joomla variables. Example of what i want to acheive :

<p> Name : </p> <h1> Name of the user who has logged in </h1>

<p> Email : </p> <h2> Email of the user who has logged in </h2>

This is what i was talking about, assigning <h1> tag to the Name of the user or assigning <h2> to Email etc.

Is there anyway to connect a HTML page to the Joomla database & retrieve data from it & display it in this fashion.

share|improve this question
1  
If you were to use ajax, you could display the information on a html page, but you'd still need to use a PHP file to send the information to the HTML page. –  moomoochoo May 18 at 11:02

1 Answer 1

up vote 6 down vote accepted

Ok for starters, you can't use a .html site to display user information, instead you will require a .php file.

Once created, you will need to import the Joomla CMS like so:

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/' ));  
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
$app = JFactory::getApplication('site');

You may have to change line 2 of the code above depending on where the root of your Joomla site is relative to your custom PHP file.

Now to get the user name and email of the current user logged in, simply add the following code below:

$user = JFactory::getUser();

echo "<p>Name: " . $user->username . "</p>";
echo "<h1>Name of the user who has logged in </h1>";

echo "<p>Email: " . $user->email . "</p>"; 
echo "<h2>Email of the user who has logged in </h2>";

So you overall file will look like this:

<?php
   define( '_JEXEC', 1 );
   define( 'JPATH_BASE', realpath(dirname(__FILE__).'/' ));  
   require_once ( JPATH_BASE .'/includes/defines.php' );
   require_once ( JPATH_BASE .'/includes/framework.php' );

   $user = JFactory::getUser();

   echo "<p>Name: " . $user->username . "</p>";
   echo "<h1>Name of the user who has logged in </h1>";

   echo "<p>Email: " . $user->email . "</p>"; 
   echo "<h2>Email of the user who has logged in </h2>";    
?>
share|improve this answer
    
first it gave me a blank page & now i moved it to the templates folder, it giving me a simple HTML OUTPUT? It's simply showing, Name of the user who has logged in instead of the actual user who has logged in? –  Saibbyweb May 18 at 10:56
    
Did you create a html or php file? How are you calling the file, typing in the URL to the path? Did you change the second line of the first code snippet as I mentioned in my answer? please make sure you follow the instructions given carefully as this does work –  Lodder May 18 at 11:10
    
i created a .PHP file & i am simply typing the URL to the path. i have placed the php file at the root of my website & i have replaced the second line with what it's written in my INDEX.PHP file define('JPATH_BASE', __DIR__); –  Saibbyweb May 18 at 11:25
    
lodder do you think this will work without instantiating the whole cms application? I think this a bit more complex... –  Chad Windnagle May 18 at 12:17
    
@ChadWindnagle - ahh my bad. forgot 1 line which I've now added. Test and working fully –  Lodder May 18 at 13:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.