Accessing session data outside Joomla

前端 未结 15 1506
小鲜肉
小鲜肉 2020-12-08 03:36

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

15条回答
  •  难免孤独
    2020-12-08 04:01

    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.)

提交回复
热议问题