I'm in the process of taking all of my loose functions just lying around in my site and putting them in utility classes. This includes session stuff...
It all was working fine, but my database session handlers were not working... ok so I turned off the db handling and writing to a session file worked fine. Then I got the db handlers fixed and writing the session to the db was working fine...
Sessions were working fine... well I come back to work on the code some more, and to my surprise, all of the sudden sessions are only writing part of the data... to either the db or session file. And they are updating because when I use the database, the expiration time changes, but only part of the session data is there...
What really irks me, is that it was working perfectly fine not a few hours ago when I stopped to take a break, and come back and sessions are suddenly only partially working.
Let me be a little more clear. The only session data that is remember and saved, is session data set in the 1st file included. For example, this is basically my /index.php page:
[php]<?php
require('includes/application_top.php');
require(DIR_WS_PAGES . 'main.php');
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>[/php]
Only session data set in application_top.php is being saved when the session closes... I don't get it... none of the other session info set in the main script is being saved now... but it was just not that long ago... but now it isn't...
If it helps any, here is my session utility class:
[php]<?php
require_once(dirname(__FILE__) . '/utilities.php');
// Session Handler
if (STORE_SESSIONS == 'database') {
if (!$SESS_LIFE = get_cfg_var('session.gc_maxlifetime')) {
$SESS_LIFE = 1440;
}
if (!session_set_save_handler(
array('Session', 'dbOpen'),
array('Session', 'dbClose'),
array('Session', 'dbRead'),
array('Session', 'dbWrite'),
array('Session', 'dbDestroy'),
array('Session', 'dbGC')
)) {
trigger_error('session_set_save_handler() failed ', E_USER_ERROR);
}
}
class Session extends UtilitiesClass {
function start() {
return session_start();
}
function ID($sessid = '') {
if (!empty($sessid)) {
return session_id($sessid);
} else {
return session_id();
}
}
function name($name = '') {
if (!empty($name)) {
return session_name($name);
} else {
return session_name();
}
}
function close() {
return session_write_close();
}
function closeExit() {
Session::close();
exit();
}
function destroy() {
return session_destroy();
}
function savePath($path = '') {
if (!empty($path)) {
return session_save_path($path);
} else {
return session_save_path();
}
}
function dbOpen($save_path, $session_name) {
return true;
}
function dbClose() {
return true;
}
function dbRead($sesskey) {
global $db;
$db->query(QueryHelper::select('value', TABLE_SESSIONS, "sesskey = '" . $sesskey . "' and expiry > '" . time() . "'"));
$read_value = $db->getNext();
if (String::notNull($read_value['value'])) {
return $read_value['value'];
}
return false;
}
function dbWrite($sesskey, $value) {
global $SESS_LIFE, $db;
$expiry = time() + $SESS_LIFE;
$db->query(QueryHelper::select('count(*) as total', TABLE_SESSIONS, "sesskey = '" . $sesskey . "'"));
$count = $db->getNext();
if ($count['total'] > 0) {
$update_sql_array = array(
'expiry' => $expiry,
'value' => $value,
);
return $db->query(QueryHelper::update(TABLE_SESSIONS, $update_sql_array, "sesskey = '" . $sesskey . "'"));
} else {
$insert_sql_array = array(
'sesskey' => $sesskey,
'expiry' => $expiry,
'value' => $value,
);
return $db->query(QueryHelper::insert(TABLE_SESSIONS, $insert_sql_array));
}
}
function dbDestroy($sesskey) {
global $db;
return $db->query(QueryHelper::delete(TABLE_SESSIONS, "sesskey = '" . $sesskey . "'"));
}
function dbGC($maxlifetime) {
global $db;
return $db->query(QueryHelper::delete(TABLE_SESSIONS, "expiry < '" . time() . "'"));
}
}
?>[/php]
If anyone has any ideas I sure would appreciate it.