]> git.mxchange.org Git - friendica.git/blob - include/session.php
FR update to the strings THX Perig
[friendica.git] / include / session.php
1 <?php
2
3 // Session management functions. These provide database storage of PHP
4 // session info.
5
6 $session_exists = 0;
7 $session_expire = 180000;
8
9 if(! function_exists('ref_session_open')) {
10 function ref_session_open ($s,$n) {
11   return true;
12 }}
13
14 if(! function_exists('ref_session_read')) {
15 function ref_session_read ($id) {
16   global $session_exists;
17   if(x($id))
18     $r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
19   if(count($r)) {
20     $session_exists = true;
21     return $r[0]['data'];
22   } else {
23     logger("no data for session $id", LOGGER_TRACE);
24   }
25   return '';
26 }}
27
28 if(! function_exists('ref_session_write')) {
29 function ref_session_write ($id,$data) {
30   global $session_exists, $session_expire;
31   if(! $id || ! $data) {
32     return false;
33   }
34
35   $expire = time() + $session_expire;
36   $default_expire = time() + 300;
37
38   if($session_exists)
39     $r = q("UPDATE `session`
40             SET `data` = '%s', `expire` = '%s'
41             WHERE `sid` = '%s'",
42             dbesc($data), dbesc($expire), dbesc($id));
43   else
44     $r = q("INSERT INTO `session`
45             SET `sid` = '%s', `expire` = '%s', `data` = '%s'",
46             dbesc($id), dbesc($default_expire), dbesc($data));
47
48   return true;
49 }}
50
51 if(! function_exists('ref_session_close')) {
52 function ref_session_close() {
53   return true;
54 }}
55
56 if(! function_exists('ref_session_destroy')) {
57 function ref_session_destroy ($id) {
58   q("DELETE FROM `session` WHERE `sid` = '%s'", dbesc($id));
59   return true;
60 }}
61
62 if(! function_exists('ref_session_gc')) {
63 function ref_session_gc($expire) {
64   q("DELETE FROM `session` WHERE `expire` < %d", dbesc(time()));
65   q("OPTIMIZE TABLE `sess_data`");
66   return true;
67 }}
68
69 $gc_probability = 50;
70
71 ini_set('session.gc_probability', $gc_probability);
72 ini_set('session.use_only_cookies', 1);
73 ini_set('session.cookie_httponly', 1);
74
75
76 session_set_save_handler ('ref_session_open', 'ref_session_close',
77                             'ref_session_read', 'ref_session_write',
78                             'ref_session_destroy', 'ref_session_gc');