$user = JFactory::getUser(); echo "User name: " . $user->name; echo "User email: " . $user->email;
$user = JFactory::getUser(); if ($user->guest) { echo "You need to be logged in to access this page."; } else { echo "Welcome, " . $user->name . "!"; }This example checks if the user is logged in by using the `$user->guest` property. If they are not logged in, it displays a message prompting them to log in. If they are logged in, it displays a welcome message with their name. The `JFactory` class is a part of the Joomla Framework, which is a package library that provides a set of tools and components for building web applications using the Joomla CMS.