简体   繁体   中英

access joomla session in php - codeigniter

I need to check if the user is logged in or not in CodeIgniter.

The login is happening in Joomla site.

I tried the following to initialize joomla .

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(__FILE__) );

require_once ("../includes/defines.php");
require_once ("../includes/framework.php");

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

$session =& JFactory::getSession();
$user = $session->get( 'user' );

But I got this message:

No configuration file found and no installation code available. Exiting...

Joomla is installed on root and codeigniter on root/advanced

I am calling the code in controller.

How can I solve this?

EDIT:

Now I am getting this error:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: BM

Filename: core/CodeIgniter.php

Line Number: 364

Edit

My Controller look like this

function is_logged()
    {

                define( '_JEXEC', 1 );
            define( 'JPATH_BASE', '../');
            define( 'DS', DIRECTORY_SEPARATOR );

        require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
        require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
        //require_once ("../libraries/joomla/user/authentication.php");
        $mainframe =& JFactory::getApplication("site");
        $mainframe->initialise();

        $session =& JFactory::getSession();
        $user = $session->get( 'user' );



    }

Directory Structure

--Public_html
  --Joomla Istallation files
  --Advanced [This is a folder ,i installed codeignitor on this folder]

So the path to joomla is site.com/ and path to Codeignitor is site.com/advanced

More about the Error

Line 364 on Codeignitor Core says that :

// Mark a benchmark end point
    $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');

and i can see the following on the starting of CI core

    $BM =& load_class('Benchmark', 'core');
    $BM->mark('total_execution_time_start');
    $BM->mark('loading_time:_base_classes_start');

I know its an old post but you need to make sure JPATH_BASE points to the directory where your configuration.php file is. I would use the absolute path rather than a relative path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM