只将用户会话记录到Joomla后端


Get User Session logged only to Joomla Backend

我使用的是Joomla 2.5.27,我需要创建一个php并在后台获取登录用户的会话。

我有我在网站上找到的代码

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(dirname(__FILE__))));
require_once ( JPATH_BASE . '/includes/defines.php' );
require_once ( JPATH_BASE . '/includes/framework.php' );
$mainframe =& JFactory::getApplication('administrator');
$mainframe->initialise();
$user =& JFactory::getUser();
$session =& JFactory::getSession();
header('Content-Type: application/json');
echo json_encode($session);

因此,如果用户登录到前端,那么它会返回已登录的用户。但如果只记录到后端,则此代码将返回guest用户。

有人能解释一下是否可以获得后台会话吗
带有上面代码的php文件位于管理员路径

通过从浏览器中清除cookie解决了问题,现在它工作得非常好,而且总是!