XOOPS  2.6.0
Handler.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
12 namespace Xoops\Core\Session;
13 
26 class Handler implements \SessionHandlerInterface
27 {
31  private $db;
32 
36  private $sessionTable = 'system_session';
37 
41  public function __construct()
42  {
43  $this->db = \Xoops::getInstance()->db();
44  }
45 
54  public function open($save_path, $name)
55  {
56  return true;
57  }
58 
64  public function close()
65  {
66  return true;
67  }
68 
76  public function read($session_id)
77  {
78  $qb = $this->db->createXoopsQueryBuilder();
79  $eb = $qb->expr();
80  $qb ->select('s.session_data')
81  ->fromPrefix($this->sessionTable, 's')
82  ->where($eb->eq('s.session_id', ':sessid'))
83  ->andWhere($eb->gt('s.expires_at', ':expires'))
84  ->setParameter(':sessid', $session_id, \PDO::PARAM_STR)
85  ->setParameter(':expires', time(), \PDO::PARAM_INT);
86 
87  $session_data = '';
88  if ($result = $qb->execute()) {
89  if ($row = $result->fetch(\PDO::FETCH_NUM)) {
90  list ($session_data) = $row;
91  }
92  }
93 
94  // if system is not configured for garbage collect, force it anyway
95  if ((ini_get('session.gc_probability') == 0) && (rand(1, 100) <= 5)) {
96  $this->gc(0);
97  }
98 
99  return $session_data;
100  }
101 
110  public function write($session_id, $session_data)
111  {
112  $expires = (isset($_SESSION['SESSION_MANAGER_EXPIRES']))
113  ? intval($_SESSION['SESSION_MANAGER_EXPIRES'])
114  : time() + (session_cache_expire() * 60);
115  $qb = $this->db->createXoopsQueryBuilder();
116  $eb = $qb->expr();
117  $qb ->updatePrefix($this->sessionTable)
118  ->set('expires_at', ':expires')
119  ->set('session_data', ':sessdata')
120  ->where($eb->eq('session_id', ':sessid'))
121  ->setParameter(':sessid', $session_id, \PDO::PARAM_STR)
122  ->setParameter(':expires', $expires, \PDO::PARAM_INT)
123  ->setParameter(':sessdata', $session_data, \PDO::PARAM_STR);
124  $this->db->setForce(true);
125  $result = $qb->execute();
126  if ($result<=0) {
127  $qb = $this->db->createXoopsQueryBuilder();
128  $qb ->insertPrefix($this->sessionTable)
129  ->values(array(
130  'session_id' => ':sessid',
131  'expires_at' => ':expires',
132  'session_data' => ':sessdata',
133  ))
134  ->setParameter(':sessid', $session_id, \PDO::PARAM_STR)
135  ->setParameter(':expires', $expires, \PDO::PARAM_INT)
136  ->setParameter(':sessdata', $session_data, \PDO::PARAM_STR);
137  $this->db->setForce(true);
138  $result = $qb->execute();
139  }
140 
141  return ($result);
142  }
143 
151  public function destroy($session_id)
152  {
153  $qb = $this->db->createXoopsQueryBuilder();
154  $eb = $qb->expr();
155  $qb ->deletePrefix($this->sessionTable)
156  ->where($eb->eq('session_id', ':sessid'))
157  ->setParameter(':sessid', $session_id, \PDO::PARAM_STR);
158  $this->db->setForce(true);
159  return $qb->execute();
160  }
161 
169  public function gc($maxlifetime)
170  {
171  $mintime = time();
172  $qb = $this->db->createXoopsQueryBuilder();
173  $eb = $qb->expr();
174  $qb ->deletePrefix($this->sessionTable)
175  ->where($eb->lt('expires_at', ':expires'))
176  ->setParameter(':expires', $mintime, \PDO::PARAM_INT);
177  $this->db->setForce(true);
178  return $qb->execute();
179  }
180 }
db()
Definition: Xoops.php:175
$_SESSION['RF']["verify"]
Definition: dialog.php:4
open($save_path, $name)
Definition: Handler.php:54
write($session_id, $session_data)
Definition: Handler.php:110
static getInstance()
Definition: Xoops.php:160
$result
Definition: pda.php:33
if(empty($mimetype)) $expires
Definition: browse.php:97