9

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.

1
  • 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.
    – TryHarder
    May 18, 2014 at 11:02

1 Answer 1

9

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>";    
?>
8
  • 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, 2014 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, 2014 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, 2014 at 11:25
  • lodder do you think this will work without instantiating the whole cms application? I think this a bit more complex... May 18, 2014 at 12:17
  • @ChadWindnagle - ahh my bad. forgot 1 line which I've now added. Test and working fully
    – Lodder
    May 18, 2014 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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