i have this custom php page example for Joomla 4.. that i can access from the root of my site mysite.com/custom.php
Code: Select all
<?php
define('_JEXEC', 1);
use Joomla\CMS\Factory;
//Root Page - // save and run from the main joomla folder
define('JPATH_BASE', realpath(dirname(__FILE__) . '../'));
//Sub Folder - // save and run from a subfolder under the main joomla folder
//define('JPATH_BASE', realpath(dirname(__FILE__) . '/..'));
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
$crlf = PHP_EOL;
$app = new Joomla\CMS\Application\SiteApplication();
\Joomla\CMS\Factory::$application = $app;
// database connection
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query
->select('COUNT(*)')
->from($db->quoteName('#__users'));
$db->setQuery($query);
$count = $db->loadResult();
echo 'PHP version ' . phpversion() . $crlf;
echo $count . ' users' . $crlf;
?>
Code: Select all
$user = JFactory::getUser();
echo $user->id;
thank you