1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
if (STORE_SESSIONS == 'mysql')
{
if (!$SESS_LIFE = get_cfg_var('session.gc_maxlifetime')) $SESS_LIFE = 1440;
function _sess_open($save_path, $session_name) {
return true;
}
function _sess_close() {
return true;
}
function _sess_read($key)
{
$qid = tep_db_query("select value from b_sessions where sesskey = '" . tep_db_input($key) . "' and expiry > '" . time() . "'");
$value = tep_db_fetch_array($qid);
if ($value['value']) return $value['value'];
return false;
}
function _sess_write($key, $val)
{
global $SESS_LIFE;
$expiry = time() + $SESS_LIFE;
$value = $val;
$qid = tep_db_query("select count(*) as total from b_sessions where sesskey = '" . tep_db_input($key) . "'");
$total = tep_db_fetch_array($qid);
if ($total['total'] > 0) return tep_db_query("update b_sessions set expiry = '" . tep_db_input($expiry) . "', value = '" . tep_db_input($value) . "' where sesskey = '" . tep_db_input($key) . "'");
else return tep_db_query("insert into b_sessions values ('" . tep_db_input($key) . "', '" . tep_db_input($expiry) . "', '" . tep_db_input($value) . "')");
}
function _sess_destroy($key) {
return tep_db_query("delete from b_sessions where sesskey = '" . tep_db_input($key) . "'");
}
function _sess_gc($maxlifetime) {
tep_db_query("delete from b_sessions where expiry < '" . time() . "'");
return true;
}
session_set_save_handler('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
}
Structure des tables des sessions
b_sessions
(
sesskey varchar(32) NOT NULL,
expiry int(11) unsigned NOT NULL,
value text NOT NULL,
PRIMARY KEY (sesskey)
)
c_sessions
(
sesskey varchar(32) NOT NULL,
expiry int(11) unsigned NOT NULL,
value text NOT NULL,
PRIMARY KEY (sesskey)
) |
Partager