2

I am trying to achieve single sign on behaviors between PHP/PERL applications and Joomla. The main entry point would be Joomla, which would set up the sessions and other cookie variables that would be used by the external Perl and PHP applications. For PHP Applications, I have used the below code after reading and researching, to check whether the Joomla session is Active.

 $rootFolder = explode(DS,dirname(__FILE__));
  $currentfolderlevel = 1;
  array_splice($rootFolder,-$currentfolderlevel);
  $base_folder = implode(DS,$rootFolder);
  $base_folder= $base_folder.'/'.'xxx';
  array_push($rootFolder, "/xxx");
 if(is_dir($base_folder .DS.'libraries'.DS.'joomla'))   
 {
   define( '_JEXEC', 1 );
   define('JPATH_BASE',implode(DS,$rootFolder));
   require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
   require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

jimport( 'joomla.user.user');
jimport( 'joomla.session.session');
jimport( 'joomla.user.authentication');
        $mainframe = JFactory::getApplication('site');
        $mainframe->initialise();
        $user =JFactory::getUser();
        $session = JFactory::getSession();
        //$groups  = $options['user']->groups;
        $session = JFactory::getSession();
        $sessionState=$session->getState();
        $sessionExpiry=$session->getName();

The above code works fine as in, it checks the session if its active then lets the user work on external PHP app. The problem is that if I am not using the main Joomla site and am only working on the external PHP application, the session on the main joomla website expires hence leading to the logout on the external php application.

My Question is, how do I manage sessions between both the external and the main Joomla site?

I am sorry for the long post . I would really appreciate any help on this.

Many Thanks, Teju

  • Hi, I would really appreciate any suggestion on this please. Have been trying all sorts of different ways. – Teju Desai Jul 24 '17 at 6:52
0

Just keep the session alive by pinging Joomla via JS:

<script>
setInterval(function(){

    var xhttp = new XMLHttpRequest();
    xhttp.open('get', 'https://yourdomain.tld/index.php', true);
    xhttp.send();

    },30000);
</script>
  • Ok , so this javascript file will be included for all the the perl/php scripts. Why didn't i think of this.... <br> I will try and let you know .Thanks Teju. – Teju Desai Aug 7 '17 at 10:03
  • You can test it by setting the session time to 1 in the Joomla global configuration. Later change the time interval in the script closer to your real session time to save performance. – Dennis Heiden Aug 7 '17 at 10:07
  • If this was the correct answer to you problem, please mark my answer as correct. Thank you! – Dennis Heiden Aug 8 '17 at 13:36
  • Sorry, I had been away. I am just testing the solution now. I would do the required after i have finished testing. – Teju Desai Aug 16 '17 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.