【问题标题】:joomla factory get userjoomla工厂获取用户
【发布时间】:2017-06-18 22:20:03
【问题描述】:

您好,我在我的应用程序上收到以下错误消息,该应用程序在 joomla 应用程序的 iframe 中运行并从 joomla 会话获取用户详细信息:

警告:ini_set():会话处于活动状态。您不能更改会话 此时模块的ini设置在 /home/sites/accstats.co.uk/public_html/libraries/joomla/session/handler/joomla.php 在第 45 行 id:973

这是我正在使用的代码,它对于旧版本的 joomla 一直运行良好,我不是开发人员(只是业余爱好者)所以不确定问题出在哪里。

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', "/home/sites/accstats.co.uk/public_html/" );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe = JFactory::getApplication('site');
$mainframe->initialise();

$user = JFactory::getUser();

if($user->id)


// log in
{
        $_SESSION["UserID"] = $user->get("username");
        $groups = $user->get('groups');
        $_SESSION["GroupID"] = reset($groups);
        $_SESSION["UserName"] = $user->get("name");
        if ($user->get('isRoot')) $_SESSION["AccessLevel"] = ACCESS_LEVEL_ADMINGROUP;
        else $_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;
}
else 
// log out
{
        $_SESSION["UserID"] = "";
        $_SESSION["AccessLevel"] = "";
        $_SESSION["GroupID"] = "";
        $_SESSION["UserName"] = "";
}

【问题讨论】:

标签: php joomla


【解决方案1】:

我遇到了同样的问题。当我搬到实时服务器时,我的 AJAX 文件都没有工作。花了几个小时后,我发现这是一个 URL 问题。所以通过更正 JPATH_BASE 来解决这个问题。我看到你已经给出了该参数的绝对路径。为什么不这样定义:

define( '_JEXEC', 1 );

define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../../..' ));

// including the main joomla files
require_once ( JPATH_BASE . '/includes/defines.php' );
require_once (  JPATH_BASE . '/includes/framework.php' );
require_once (  JPATH_BASE . '/configuration.php' );

// Creating an app instance
$app = JFactory::getApplication('site');
$app->initialise();
jimport( 'joomla.user.user' );
jimport( 'joomla.user.helper' );

如果它不适合您,您可以在代码行 2 更改斜杠的数量。我复制并粘贴了我遇到问题的应用程序的标题并解决了它。希望它也对你有用。

【讨论】:

    猜你喜欢
    • 2019-12-28
    • 1970-01-01
    • 2013-09-24
    • 2011-01-13
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多