Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从外部模块使用Joomla会话?_Php_Joomla - Fatal编程技术网

Php 如何从外部模块使用Joomla会话?

Php 如何从外部模块使用Joomla会话?,php,joomla,Php,Joomla,我在Jooma为我的网站创建了一个外部模块。我需要检查用户是否已登录,因此我尝试加载文件/libraries/import.php,以便使用JFactory::getSession(),但它在某一点上存在 我该怎么做 多谢各位 Egidio试试这个 外部模块是指joomla之外的纯php文件,对吗?或者是joomla模块?。 如果是如下所示的外部文件 define( '_JEXEC', 1 ); define('JPATH_BASE', dirname(__FILE__) );//this is

我在Jooma为我的网站创建了一个外部模块。我需要检查用户是否已登录,因此我尝试加载文件/libraries/import.php,以便使用
JFactory::getSession()
,但它在某一点上存在

我该怎么做

多谢各位

Egidio

试试这个

外部模块是指joomla之外的纯php文件,对吗?或者是joomla模块?。 如果是如下所示的外部文件

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );

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

$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
$session     = JFactory::getSession();
$user = JFactory::getUser();

if($user->id > 0)
      echo "Logged In";
else
    echo "Not logged In";
其joomla模块类似于

 $user = JFactory::getUser();

    if($user->id > 0)
          echo "Logged In";
    else
        echo "Not logged In";

希望对您有所帮助。

因此您尝试加载import.php…这样做正确吗?你从中得到了什么错误吗?您正在使用的其他代码是否有任何错误?你能提供更多你正在使用的代码片段吗?谢谢你的回答。实际上,我已登录,但我知道JUser的ID等于零。*cough*
&
*cough*@Aegidius用户ID为0?@Lodder您的意思是什么?在
$mainframe=&JFactory::
中,您不需要使用
&
。它可以被移除