简体   繁体   English

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

[英]How can I use Joomla session from an external module?

I've created an external module for my website in Jooma. 我为Jooma的网站创建了一个外部模块。 I need to check if the user is logged, so I tried to load the file /libraries/import.php in order to use JFactory::getSession() but it exists in some point. 我需要检查用户是否已登录,因此为了使用JFactory::getSession() ,我尝试加载文件/libraries/import.php ,但是它在某些时候存在。

How can I do that? 我怎样才能做到这一点?

Thank you. 谢谢。

Egidio 埃吉迪奥

try this, 尝试这个,

External Module means pure php file outside joomla right ? 外部模块意味着joomla之外的纯php文件,对吗? or its a joomla module ?. 或其joomla模块? If it is external file like below. 如果是如下所示的外部文件。

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";

Its joomla module like 它的joomla模块像

 $user = JFactory::getUser();

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

Hope it helps.. 希望能帮助到你..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 DbManager 获取 Yii2 RBAC 使用 Joomla“用户”表和 Joomla 会话中的用户 ID? - How do I get Yii2 RBAC via DbManager use Joomla "user" table and userid from Joomla session? 如何在Joomla 1.5中的模块中使用内置的pdf函数 - How can I use a built-in pdf function in a module in Joomla 1.5 如何将来自外部Web服务的分类内容集成到Joomla 1.5中? - How can I integrate categorized content from an external web service into Joomla 1.5? 如何获取会话数据(来自外部PHP脚本)而不被Joomla会话覆盖? - How to get session data (from external php script) without being overwritten by Joomla session? 如何在 Joomla 中使用 HttpFactory? - How can I use HttpFactory in Joomla? 如果用户在 javascript 应用程序在 Z226776F3561A5D33FZ0BAB 中仍然处于活动状态,我如何扩展 Joomla session? - How can i extend Joomla session if user still active on client javascript application in joomla? 如何使Joomla模块显示实时数据? - How can I make a Joomla module show live data? 如何从外部PHP脚本编写/读取joomla会话变量时防止竞争条件? - How to prevent race conditions when writing/ reading joomla session variables from an external php script? 如何使用PHP $ _SESSION中的jquery sessionStorage值? - How can i use jquery sessionStorage value from PHP $_SESSION? 在Joomla中使用外部扩展 - Use external extensions in Joomla
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM