3 // Session management functions. These provide database storage of PHP
7 $session_expire = 180000;
9 if(! function_exists('ref_session_open')) {
10 function ref_session_open ($s,$n) {
14 if(! function_exists('ref_session_read')) {
15 function ref_session_read ($id) {
16 global $session_exists;
18 $r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
20 $session_exists = true;
26 if(! function_exists('ref_session_write')) {
27 function ref_session_write ($id,$data) {
28 global $session_exists, $session_expire;
29 if(! $id || ! $data) {
33 $expire = time() + $session_expire;
34 $default_expire = time() + 300;
37 $r = q("UPDATE `session`
38 SET `data` = '%s', `expire` = '%s'
39 WHERE `sid` = '%s' LIMIT 1",
40 dbesc($data), dbesc($expire), dbesc($id));
42 $r = q("INSERT INTO `session`
43 SET `sid` = '%s', `expire` = '%s', `data` = '%s'",
44 dbesc($id), dbesc($default_expire), dbesc($data));
49 if(! function_exists('ref_session_close')) {
50 function ref_session_close() {
54 if(! function_exists('ref_session_destroy')) {
55 function ref_session_destroy ($id) {
56 q("DELETE FROM `session` WHERE `sid` = '%s'", dbesc($id));
60 if(! function_exists('ref_session_gc')) {
61 function ref_session_gc($expire) {
62 q("DELETE FROM `session` WHERE `expire` < %d", dbesc(time()));
63 q("OPTIMIZE TABLE `sess_data`");
69 ini_set('session.gc_probability', $gc_probability);
70 ini_set('session.use_only_cookies', 1);
71 ini_set('session.cookie_httponly', 1);
74 session_set_save_handler ('ref_session_open', 'ref_session_close',
75 'ref_session_read', 'ref_session_write',
76 'ref_session_destroy', 'ref_session_gc');