I am trying to run an application outside Joomla (not as a plugin) and I would like to access the logged in user\'s information (userid). I am wondering how should I go abou
A solution for Joomla 3, without using any libraries.
require_once '../configuration.php'; // load Joomla configuration file
$jConfig = new \JConfig();
$secret = $jConfig->secret;
$dbprefix = $jConfig->dbprefix;
$cookieName = md5(md5($secret . 'site'));
$sessionId = $_COOKIE[$cookieName];
$sql = "select userid from {$dbprefix}session where client_id = 0 and session_id = ?";
$userId = $db->lookup($sql, [$sessionId]);
(The code above is simplified, without any error handling.)