3

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

1
  • Hi, I would really appreciate any suggestion on this please. Have been trying all sorts of different ways. Commented Jul 24, 2017 at 6:52

1 Answer 1

1

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> 
4
  • 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. Commented Aug 7, 2017 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. Commented Aug 7, 2017 at 10:07
  • If this was the correct answer to you problem, please mark my answer as correct. Thank you! Commented Aug 8, 2017 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. Commented Aug 16, 2017 at 6:54

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.