3

Joomla 1.5.25 just upgraded from 1.5.23 having problems saving to session and persistency, works perfectly on 1.5.23, but session data is not being saved to db when using JSession->set

Wrote custom app on top of joomla, managing users imported from legacy system cant use joomla Users for this ( or at least I haven't and I dont have the time ), login works like follows:

  1. User posts email pass
  2. app checks if user exists
  3. if user exists I save the user object to session
  4. redirect user to resource

Here is the snippet for saving the user to session

$session   = JFactory::getSession();
$session->set('appUserData', array(
    'data' => $USER_OBJECT,
    'timestamp' => time(),
    'role' => 0,
    'permits' => $permits
);, "custom_namespace");

Now since I'm doing this outside the joomla scope I have to boostrap

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

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

Once I do $session->set() if I try $session->get() on the same script it does pull the full resource I just saved, but if I try to pull the $session from another script I get nothing, here is the Other script

<?php 
error_reporting(E_ALL);
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(dirname(__FILE__)));

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

$mainframe = JFactory::getApplication('site');
$session   = JFactory::getSession();

echo "<pre>";
print_r($_COOKIE);
print_r($session);
print_r($_SESSION);
echo "</pre>";
exit;

Here I only get my cookies array and the Array of the session with the default session info:

Array
(
    [__default] => Array
        (
            [session.counter] => 3
            [session.timer.start] => 1329168055
            [session.timer.last] => 1329168057
            [session.timer.now] => 1329168062
            [session.client.browser] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.1) Gecko/20100101 Firefox/10.0.1 FirePHP/0.7.0
        )

)

The db never gets updated with the contents of my newly created session variable, I tried doing some error_logs on the write db session adapter which is the one writing to db, and I think the problem is here ( libraries/joomla/session/storage/database.php ) line 82:

$session = &JTable::getInstance('session');
if ($session->load($id) == true) { /*...*/} // never entering here
else { /*...*/ } // always here

I tried outputting to the log the contents of $id and It does refer to a valid primary key id on the db

error_log('SELECT * FROM jos_session WHERE session_id = "' . $id . '"');

returns something like this SELECT * FROM jos_session WHERE session_id = "38e6468f35f1994425de3919fa767a3d", which I can confirm returns a valid record, I tried pulling the old source from 1.5.23 here but even that wont make it work again, any ideas out there on what might have upgraded and made this fail?

**UPDATE**

I tried truncating the tables too, in fact I think the problem more specifically is that at some point the session fails on write to db, since I have multiple connections to mysql being used, the JSession Database Mysql Storage engine for the session gets confused, even weirder is that on an environment with pure 1.5.23 this confusion doesn't occur, resources get created for each different connection, I went trough the changes from 1.5.23 to 1.5.25 and I can't find anything related to DB resource management or any loose reference to the DBO object, I think I need to profile each connection and check where is the problem, Data lives on same mysql server but on different db's

rroche
  • 1,262
  • 1
  • 13
  • 29

1 Answers1

0

Problem is JSession is using the database storage JsessionStorageDatabase since I'm connecting to multiple databases through out the script execution my mysql_connect calls weren't really making a new connection, they were reusing the old causing the script to fail when it didn't find the selected db which changed by the time the Storage adapter for JSession wanted to do a write

See mysql_connect documentation here and check this question from another user which helped me understand my problem and come to a solution

Community
  • 1
  • 1
rroche
  • 1,262
  • 1
  • 13
  • 29