| 68 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* CodeIgniter
|
|
|
4 |
*
|
|
|
5 |
* An open source application development framework for PHP
|
|
|
6 |
*
|
|
|
7 |
* This content is released under the MIT License (MIT)
|
|
|
8 |
*
|
| 2414 |
lars |
9 |
* Copyright (c) 2014 - 2019, British Columbia Institute of Technology
|
| 68 |
lars |
10 |
*
|
|
|
11 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
12 |
* of this software and associated documentation files (the "Software"), to deal
|
|
|
13 |
* in the Software without restriction, including without limitation the rights
|
|
|
14 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
15 |
* copies of the Software, and to permit persons to whom the Software is
|
|
|
16 |
* furnished to do so, subject to the following conditions:
|
|
|
17 |
*
|
|
|
18 |
* The above copyright notice and this permission notice shall be included in
|
|
|
19 |
* all copies or substantial portions of the Software.
|
|
|
20 |
*
|
|
|
21 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
22 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
23 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
24 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
25 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
26 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
27 |
* THE SOFTWARE.
|
|
|
28 |
*
|
|
|
29 |
* @package CodeIgniter
|
|
|
30 |
* @author EllisLab Dev Team
|
|
|
31 |
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
| 2414 |
lars |
32 |
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
|
|
33 |
* @license https://opensource.org/licenses/MIT MIT License
|
| 68 |
lars |
34 |
* @link https://codeigniter.com
|
|
|
35 |
* @since Version 3.0.0
|
|
|
36 |
* @filesource
|
|
|
37 |
*/
|
|
|
38 |
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* CodeIgniter Session Driver Class
|
|
|
42 |
*
|
|
|
43 |
* @package CodeIgniter
|
|
|
44 |
* @subpackage Libraries
|
|
|
45 |
* @category Sessions
|
|
|
46 |
* @author Andrey Andreev
|
|
|
47 |
* @link https://codeigniter.com/user_guide/libraries/sessions.html
|
|
|
48 |
*/
|
|
|
49 |
abstract class CI_Session_driver implements SessionHandlerInterface {
|
|
|
50 |
|
|
|
51 |
protected $_config;
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Data fingerprint
|
|
|
55 |
*
|
|
|
56 |
* @var bool
|
|
|
57 |
*/
|
|
|
58 |
protected $_fingerprint;
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Lock placeholder
|
|
|
62 |
*
|
|
|
63 |
* @var mixed
|
|
|
64 |
*/
|
|
|
65 |
protected $_lock = FALSE;
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Read session ID
|
|
|
69 |
*
|
|
|
70 |
* Used to detect session_regenerate_id() calls because PHP only calls
|
|
|
71 |
* write() after regenerating the ID.
|
|
|
72 |
*
|
|
|
73 |
* @var string
|
|
|
74 |
*/
|
|
|
75 |
protected $_session_id;
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Success and failure return values
|
|
|
79 |
*
|
|
|
80 |
* Necessary due to a bug in all PHP 5 versions where return values
|
|
|
81 |
* from userspace handlers are not handled properly. PHP 7 fixes the
|
|
|
82 |
* bug, so we need to return different values depending on the version.
|
|
|
83 |
*
|
|
|
84 |
* @see https://wiki.php.net/rfc/session.user.return-value
|
|
|
85 |
* @var mixed
|
|
|
86 |
*/
|
|
|
87 |
protected $_success, $_failure;
|
|
|
88 |
|
|
|
89 |
// ------------------------------------------------------------------------
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Class constructor
|
|
|
93 |
*
|
|
|
94 |
* @param array $params Configuration parameters
|
|
|
95 |
* @return void
|
|
|
96 |
*/
|
|
|
97 |
public function __construct(&$params)
|
|
|
98 |
{
|
|
|
99 |
$this->_config =& $params;
|
|
|
100 |
|
|
|
101 |
if (is_php('7'))
|
|
|
102 |
{
|
|
|
103 |
$this->_success = TRUE;
|
|
|
104 |
$this->_failure = FALSE;
|
|
|
105 |
}
|
|
|
106 |
else
|
|
|
107 |
{
|
|
|
108 |
$this->_success = 0;
|
|
|
109 |
$this->_failure = -1;
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
// ------------------------------------------------------------------------
|
|
|
114 |
|
|
|
115 |
/**
|
| 2414 |
lars |
116 |
* PHP 5.x validate ID
|
|
|
117 |
*
|
|
|
118 |
* Enforces session.use_strict_mode
|
|
|
119 |
*
|
|
|
120 |
* @return void
|
|
|
121 |
*/
|
|
|
122 |
public function php5_validate_id()
|
|
|
123 |
{
|
|
|
124 |
if (isset($_COOKIE[$this->_config['cookie_name']]) && ! $this->validateSessionId($_COOKIE[$this->_config['cookie_name']]))
|
|
|
125 |
{
|
|
|
126 |
unset($_COOKIE[$this->_config['cookie_name']]);
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
// ------------------------------------------------------------------------
|
|
|
131 |
|
|
|
132 |
/**
|
| 68 |
lars |
133 |
* Cookie destroy
|
|
|
134 |
*
|
|
|
135 |
* Internal method to force removal of a cookie by the client
|
|
|
136 |
* when session_destroy() is called.
|
|
|
137 |
*
|
|
|
138 |
* @return bool
|
|
|
139 |
*/
|
|
|
140 |
protected function _cookie_destroy()
|
|
|
141 |
{
|
|
|
142 |
return setcookie(
|
|
|
143 |
$this->_config['cookie_name'],
|
|
|
144 |
NULL,
|
|
|
145 |
1,
|
|
|
146 |
$this->_config['cookie_path'],
|
|
|
147 |
$this->_config['cookie_domain'],
|
|
|
148 |
$this->_config['cookie_secure'],
|
|
|
149 |
TRUE
|
|
|
150 |
);
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
// ------------------------------------------------------------------------
|
|
|
154 |
|
|
|
155 |
/**
|
|
|
156 |
* Get lock
|
|
|
157 |
*
|
|
|
158 |
* A dummy method allowing drivers with no locking functionality
|
|
|
159 |
* (databases other than PostgreSQL and MySQL) to act as if they
|
|
|
160 |
* do acquire a lock.
|
|
|
161 |
*
|
|
|
162 |
* @param string $session_id
|
|
|
163 |
* @return bool
|
|
|
164 |
*/
|
|
|
165 |
protected function _get_lock($session_id)
|
|
|
166 |
{
|
|
|
167 |
$this->_lock = TRUE;
|
|
|
168 |
return TRUE;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
// ------------------------------------------------------------------------
|
|
|
172 |
|
|
|
173 |
/**
|
|
|
174 |
* Release lock
|
|
|
175 |
*
|
|
|
176 |
* @return bool
|
|
|
177 |
*/
|
|
|
178 |
protected function _release_lock()
|
|
|
179 |
{
|
|
|
180 |
if ($this->_lock)
|
|
|
181 |
{
|
|
|
182 |
$this->_lock = FALSE;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
return TRUE;
|
|
|
186 |
}
|
|
|
187 |
}
|