This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
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 | * |
||
9 | * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
||
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. (http://ellislab.com/) |
||
32 | * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
||
33 | * @license http://opensource.org/licenses/MIT MIT License |
||
34 | * @link http://codeigniter.com |
||
35 | * @since Version 2.0.0 |
||
36 | * @filesource |
||
37 | */ |
||
38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
||
39 | |||
40 | /** |
||
41 | * CodeIgniter Session Class |
||
42 | * |
||
43 | * @package CodeIgniter |
||
44 | * @subpackage Libraries |
||
45 | * @category Sessions |
||
46 | * @author Andrey Andreev |
||
47 | * @link http://codeigniter.com/user_guide/libraries/sessions.html |
||
48 | */ |
||
49 | class CI_Session { |
||
50 | |||
51 | /** |
||
52 | * Userdata array |
||
53 | * |
||
54 | * Just a reference to $_SESSION, for BC purposes. |
||
55 | */ |
||
56 | public $userdata; |
||
57 | |||
58 | protected $_driver = 'files'; |
||
59 | protected $_config; |
||
60 | |||
61 | // ------------------------------------------------------------------------ |
||
62 | |||
63 | /** |
||
64 | * Class constructor |
||
65 | * |
||
66 | * @param array $params Configuration parameters |
||
67 | * @return void |
||
68 | */ |
||
69 | public function __construct(array $params = array()) |
||
70 | { |
||
71 | // No sessions under CLI |
||
72 | if (is_cli()) |
||
73 | { |
||
74 | log_message('debug', 'Session: Initialization under CLI aborted.'); |
||
75 | return; |
||
76 | } |
||
77 | elseif ((bool) ini_get('session.auto_start')) |
||
78 | { |
||
79 | log_message('error', 'Session: session.auto_start is enabled in php.ini. Aborting.'); |
||
80 | return; |
||
81 | } |
||
82 | elseif ( ! empty($params['driver'])) |
||
83 | { |
||
84 | $this->_driver = $params['driver']; |
||
85 | unset($params['driver']); |
||
86 | } |
||
87 | elseif ($driver = config_item('sess_driver')) |
||
88 | { |
||
89 | $this->_driver = $driver; |
||
90 | } |
||
91 | // Note: BC workaround |
||
92 | elseif (config_item('sess_use_database')) |
||
93 | { |
||
94 | $this->_driver = 'database'; |
||
95 | } |
||
96 | |||
97 | $class = $this->_ci_load_classes($this->_driver); |
||
98 | |||
99 | // Configuration ... |
||
100 | $this->_configure($params); |
||
101 | |||
102 | $class = new $class($this->_config); |
||
103 | if ($class instanceof SessionHandlerInterface) |
||
104 | { |
||
105 | if (is_php('5.4')) |
||
106 | { |
||
107 | session_set_save_handler($class, TRUE); |
||
108 | } |
||
109 | else |
||
110 | { |
||
111 | session_set_save_handler( |
||
112 | array($class, 'open'), |
||
113 | array($class, 'close'), |
||
114 | array($class, 'read'), |
||
115 | array($class, 'write'), |
||
116 | array($class, 'destroy'), |
||
117 | array($class, 'gc') |
||
118 | ); |
||
119 | |||
120 | register_shutdown_function('session_write_close'); |
||
121 | } |
||
122 | } |
||
123 | else |
||
124 | { |
||
125 | log_message('error', "Session: Driver '".$this->_driver."' doesn't implement SessionHandlerInterface. Aborting."); |
||
126 | return; |
||
127 | } |
||
128 | |||
129 | // Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers |
||
130 | if (isset($_COOKIE[$this->_config['cookie_name']]) |
||
131 | && ( |
||
132 | ! is_string($_COOKIE[$this->_config['cookie_name']]) |
||
133 | OR ! preg_match('/^[0-9a-f]{40}$/', $_COOKIE[$this->_config['cookie_name']]) |
||
134 | ) |
||
135 | ) |
||
136 | { |
||
137 | unset($_COOKIE[$this->_config['cookie_name']]); |
||
138 | } |
||
139 | |||
140 | session_start(); |
||
141 | |||
142 | // Is session ID auto-regeneration configured? (ignoring ajax requests) |
||
143 | if ((empty($_SERVER['HTTP_X_REQUESTED_WITH']) OR strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest') |
||
144 | && ($regenerate_time = config_item('sess_time_to_update')) > 0 |
||
145 | ) |
||
146 | { |
||
147 | if ( ! isset($_SESSION['__ci_last_regenerate'])) |
||
148 | { |
||
149 | $_SESSION['__ci_last_regenerate'] = time(); |
||
150 | } |
||
151 | elseif ($_SESSION['__ci_last_regenerate'] < (time() - $regenerate_time)) |
||
152 | { |
||
153 | $this->sess_regenerate((bool) config_item('sess_regenerate_destroy')); |
||
154 | } |
||
155 | } |
||
156 | // Another work-around ... PHP doesn't seem to send the session cookie |
||
157 | // unless it is being currently created or regenerated |
||
158 | elseif (isset($_COOKIE[$this->_config['cookie_name']]) && $_COOKIE[$this->_config['cookie_name']] === session_id()) |
||
159 | { |
||
160 | setcookie( |
||
161 | $this->_config['cookie_name'], |
||
162 | session_id(), |
||
163 | (empty($this->_config['cookie_lifetime']) ? 0 : time() + $this->_config['cookie_lifetime']), |
||
164 | $this->_config['cookie_path'], |
||
165 | $this->_config['cookie_domain'], |
||
166 | $this->_config['cookie_secure'], |
||
167 | TRUE |
||
168 | ); |
||
169 | } |
||
170 | |||
171 | $this->_ci_init_vars(); |
||
172 | |||
173 | log_message('info', "Session: Class initialized using '".$this->_driver."' driver."); |
||
174 | } |
||
175 | |||
176 | // ------------------------------------------------------------------------ |
||
177 | |||
178 | /** |
||
179 | * CI Load Classes |
||
180 | * |
||
181 | * An internal method to load all possible dependency and extension |
||
182 | * classes. It kind of emulates the CI_Driver library, but is |
||
183 | * self-sufficient. |
||
184 | * |
||
185 | * @param string $driver Driver name |
||
186 | * @return string Driver class name |
||
187 | */ |
||
188 | protected function _ci_load_classes($driver) |
||
189 | { |
||
190 | // PHP 5.4 compatibility |
||
191 | interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php'); |
||
192 | |||
193 | $prefix = config_item('subclass_prefix'); |
||
194 | |||
195 | View Code Duplication | if ( ! class_exists('CI_Session_driver', FALSE)) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
196 | { |
||
197 | require_once( |
||
198 | file_exists(APPPATH.'libraries/Session/Session_driver.php') |
||
199 | ? APPPATH.'libraries/Session/Session_driver.php' |
||
200 | : BASEPATH.'libraries/Session/Session_driver.php' |
||
201 | ); |
||
202 | |||
203 | if (file_exists($file_path = APPPATH.'libraries/Session/'.$prefix.'Session_driver.php')) |
||
204 | { |
||
205 | require_once($file_path); |
||
206 | } |
||
207 | } |
||
208 | |||
209 | $class = 'Session_'.$driver.'_driver'; |
||
210 | |||
211 | // Allow custom drivers without the CI_ or MY_ prefix |
||
212 | if ( ! class_exists($class, FALSE) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php')) |
||
213 | { |
||
214 | require_once($file_path); |
||
215 | if (class_exists($class, FALSE)) |
||
216 | { |
||
217 | return $class; |
||
218 | } |
||
219 | } |
||
220 | |||
221 | if ( ! class_exists('CI_'.$class, FALSE)) |
||
222 | { |
||
223 | if (file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$class.'.php') OR file_exists($file_path = BASEPATH.'libraries/Session/drivers/'.$class.'.php')) |
||
224 | { |
||
225 | require_once($file_path); |
||
226 | } |
||
227 | |||
228 | if ( ! class_exists('CI_'.$class, FALSE) && ! class_exists($class, FALSE)) |
||
229 | { |
||
230 | throw new UnexpectedValueException("Session: Configured driver '".$driver."' was not found. Aborting."); |
||
231 | } |
||
232 | } |
||
233 | |||
234 | if ( ! class_exists($prefix.$class) && file_exists($file_path = APPPATH.'libraries/Session/drivers/'.$prefix.$class.'.php')) |
||
235 | { |
||
236 | require_once($file_path); |
||
237 | if (class_exists($prefix.$class, FALSE)) |
||
238 | { |
||
239 | return $prefix.$class; |
||
240 | } |
||
241 | else |
||
242 | { |
||
243 | log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.'); |
||
244 | } |
||
245 | } |
||
246 | |||
247 | return 'CI_'.$class; |
||
248 | } |
||
249 | |||
250 | // ------------------------------------------------------------------------ |
||
251 | |||
252 | /** |
||
253 | * Configuration |
||
254 | * |
||
255 | * Handle input parameters and configuration defaults |
||
256 | * |
||
257 | * @param array &$params Input parameters |
||
258 | * @return void |
||
259 | */ |
||
260 | protected function _configure(&$params) |
||
261 | { |
||
262 | $expiration = config_item('sess_expiration'); |
||
263 | |||
264 | if (isset($params['cookie_lifetime'])) |
||
265 | { |
||
266 | $params['cookie_lifetime'] = (int) $params['cookie_lifetime']; |
||
267 | } |
||
268 | else |
||
269 | { |
||
270 | $params['cookie_lifetime'] = ( ! isset($expiration) && config_item('sess_expire_on_close')) |
||
271 | ? 0 : (int) $expiration; |
||
272 | } |
||
273 | |||
274 | isset($params['cookie_name']) OR $params['cookie_name'] = config_item('sess_cookie_name'); |
||
275 | if (empty($params['cookie_name'])) |
||
276 | { |
||
277 | $params['cookie_name'] = ini_get('session.name'); |
||
278 | } |
||
279 | else |
||
280 | { |
||
281 | ini_set('session.name', $params['cookie_name']); |
||
282 | } |
||
283 | |||
284 | isset($params['cookie_path']) OR $params['cookie_path'] = config_item('cookie_path'); |
||
285 | isset($params['cookie_domain']) OR $params['cookie_domain'] = config_item('cookie_domain'); |
||
286 | isset($params['cookie_secure']) OR $params['cookie_secure'] = (bool) config_item('cookie_secure'); |
||
287 | |||
288 | session_set_cookie_params( |
||
289 | $params['cookie_lifetime'], |
||
290 | $params['cookie_path'], |
||
291 | $params['cookie_domain'], |
||
292 | $params['cookie_secure'], |
||
293 | TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons |
||
294 | ); |
||
295 | |||
296 | if (empty($expiration)) |
||
297 | { |
||
298 | $params['expiration'] = (int) ini_get('session.gc_maxlifetime'); |
||
299 | } |
||
300 | else |
||
301 | { |
||
302 | $params['expiration'] = (int) $expiration; |
||
303 | ini_set('session.gc_maxlifetime', $expiration); |
||
304 | } |
||
305 | |||
306 | $params['match_ip'] = (bool) (isset($params['match_ip']) ? $params['match_ip'] : config_item('sess_match_ip')); |
||
307 | |||
308 | isset($params['save_path']) OR $params['save_path'] = config_item('sess_save_path'); |
||
309 | |||
310 | $this->_config = $params; |
||
311 | |||
312 | // Security is king |
||
313 | ini_set('session.use_trans_sid', 0); |
||
314 | ini_set('session.use_strict_mode', 1); |
||
315 | ini_set('session.use_cookies', 1); |
||
316 | ini_set('session.use_only_cookies', 1); |
||
317 | ini_set('session.hash_function', 1); |
||
318 | ini_set('session.hash_bits_per_character', 4); |
||
319 | } |
||
320 | |||
321 | // ------------------------------------------------------------------------ |
||
322 | |||
323 | /** |
||
324 | * Handle temporary variables |
||
325 | * |
||
326 | * Clears old "flash" data, marks the new one for deletion and handles |
||
327 | * "temp" data deletion. |
||
328 | * |
||
329 | * @return void |
||
330 | */ |
||
331 | protected function _ci_init_vars() |
||
332 | { |
||
333 | if ( ! empty($_SESSION['__ci_vars'])) |
||
334 | { |
||
335 | $current_time = time(); |
||
336 | |||
337 | foreach ($_SESSION['__ci_vars'] as $key => &$value) |
||
338 | { |
||
339 | if ($value === 'new') |
||
340 | { |
||
341 | $_SESSION['__ci_vars'][$key] = 'old'; |
||
342 | } |
||
343 | // Hacky, but 'old' will (implicitly) always be less than time() ;) |
||
344 | // DO NOT move this above the 'new' check! |
||
345 | elseif ($value < $current_time) |
||
346 | { |
||
347 | unset($_SESSION[$key], $_SESSION['__ci_vars'][$key]); |
||
348 | } |
||
349 | } |
||
350 | |||
351 | if (empty($_SESSION['__ci_vars'])) |
||
352 | { |
||
353 | unset($_SESSION['__ci_vars']); |
||
354 | } |
||
355 | } |
||
356 | |||
357 | $this->userdata =& $_SESSION; |
||
358 | } |
||
359 | |||
360 | // ------------------------------------------------------------------------ |
||
361 | |||
362 | /** |
||
363 | * Mark as flash |
||
364 | * |
||
365 | * @param mixed $key Session data key(s) |
||
366 | * @return bool |
||
367 | */ |
||
368 | public function mark_as_flash($key) |
||
369 | { |
||
370 | if (is_array($key)) |
||
371 | { |
||
372 | for ($i = 0, $c = count($key); $i < $c; $i++) |
||
373 | { |
||
374 | if ( ! isset($_SESSION[$key[$i]])) |
||
375 | { |
||
376 | return FALSE; |
||
377 | } |
||
378 | } |
||
379 | |||
380 | $new = array_fill_keys($key, 'new'); |
||
381 | |||
382 | $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars']) |
||
383 | ? array_merge($_SESSION['__ci_vars'], $new) |
||
384 | : $new; |
||
385 | |||
386 | return TRUE; |
||
387 | } |
||
388 | |||
389 | if ( ! isset($_SESSION[$key])) |
||
390 | { |
||
391 | return FALSE; |
||
392 | } |
||
393 | |||
394 | $_SESSION['__ci_vars'][$key] = 'new'; |
||
395 | return TRUE; |
||
396 | } |
||
397 | |||
398 | // ------------------------------------------------------------------------ |
||
399 | |||
400 | /** |
||
401 | * Get flash keys |
||
402 | * |
||
403 | * @return array |
||
404 | */ |
||
405 | View Code Duplication | public function get_flash_keys() |
|
406 | { |
||
407 | if ( ! isset($_SESSION['__ci_vars'])) |
||
408 | { |
||
409 | return array(); |
||
410 | } |
||
411 | |||
412 | $keys = array(); |
||
413 | foreach (array_keys($_SESSION['__ci_vars']) as $key) |
||
414 | { |
||
415 | is_int($_SESSION['__ci_vars'][$key]) OR $keys[] = $key; |
||
416 | } |
||
417 | |||
418 | return $keys; |
||
419 | } |
||
420 | |||
421 | // ------------------------------------------------------------------------ |
||
422 | |||
423 | /** |
||
424 | * Unmark flash |
||
425 | * |
||
426 | * @param mixed $key Session data key(s) |
||
427 | * @return void |
||
428 | */ |
||
429 | View Code Duplication | public function unmark_flash($key) |
|
430 | { |
||
431 | if (empty($_SESSION['__ci_vars'])) |
||
432 | { |
||
433 | return; |
||
434 | } |
||
435 | |||
436 | is_array($key) OR $key = array($key); |
||
437 | |||
438 | foreach ($key as $k) |
||
439 | { |
||
440 | if (isset($_SESSION['__ci_vars'][$k]) && ! is_int($_SESSION['__ci_vars'][$k])) |
||
441 | { |
||
442 | unset($_SESSION['__ci_vars'][$k]); |
||
443 | } |
||
444 | } |
||
445 | |||
446 | if (empty($_SESSION['__ci_vars'])) |
||
447 | { |
||
448 | unset($_SESSION['__ci_vars']); |
||
449 | } |
||
450 | } |
||
451 | |||
452 | // ------------------------------------------------------------------------ |
||
453 | |||
454 | /** |
||
455 | * Mark as temp |
||
456 | * |
||
457 | * @param mixed $key Session data key(s) |
||
458 | * @param int $ttl Time-to-live in seconds |
||
459 | * @return bool |
||
460 | */ |
||
461 | public function mark_as_temp($key, $ttl = 300) |
||
462 | { |
||
463 | $ttl += time(); |
||
464 | |||
465 | if (is_array($key)) |
||
466 | { |
||
467 | $temp = array(); |
||
468 | |||
469 | foreach ($key as $k => $v) |
||
470 | { |
||
471 | // Do we have a key => ttl pair, or just a key? |
||
472 | if (is_int($k)) |
||
473 | { |
||
474 | $k = $v; |
||
475 | $v = $ttl; |
||
476 | } |
||
477 | else |
||
478 | { |
||
479 | $v += time(); |
||
480 | } |
||
481 | |||
482 | if ( ! isset($_SESSION[$k])) |
||
483 | { |
||
484 | return FALSE; |
||
485 | } |
||
486 | |||
487 | $temp[$k] = $v; |
||
488 | } |
||
489 | |||
490 | $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars']) |
||
491 | ? array_merge($_SESSION['__ci_vars'], $temp) |
||
492 | : $temp; |
||
493 | |||
494 | return TRUE; |
||
495 | } |
||
496 | |||
497 | if ( ! isset($_SESSION[$key])) |
||
498 | { |
||
499 | return FALSE; |
||
500 | } |
||
501 | |||
502 | $_SESSION['__ci_vars'][$key] = $ttl; |
||
503 | return TRUE; |
||
504 | } |
||
505 | |||
506 | // ------------------------------------------------------------------------ |
||
507 | |||
508 | /** |
||
509 | * Get temp keys |
||
510 | * |
||
511 | * @return array |
||
512 | */ |
||
513 | View Code Duplication | public function get_temp_keys() |
|
514 | { |
||
515 | if ( ! isset($_SESSION['__ci_vars'])) |
||
516 | { |
||
517 | return array(); |
||
518 | } |
||
519 | |||
520 | $keys = array(); |
||
521 | foreach (array_keys($_SESSION['__ci_vars']) as $key) |
||
522 | { |
||
523 | is_int($_SESSION['__ci_vars'][$key]) && $keys[] = $key; |
||
524 | } |
||
525 | |||
526 | return $keys; |
||
527 | } |
||
528 | |||
529 | // ------------------------------------------------------------------------ |
||
530 | |||
531 | /** |
||
532 | * Unmark flash |
||
533 | * |
||
534 | * @param mixed $key Session data key(s) |
||
535 | * @return void |
||
536 | */ |
||
537 | View Code Duplication | public function unmark_temp($key) |
|
538 | { |
||
539 | if (empty($_SESSION['__ci_vars'])) |
||
540 | { |
||
541 | return; |
||
542 | } |
||
543 | |||
544 | is_array($key) OR $key = array($key); |
||
545 | |||
546 | foreach ($key as $k) |
||
547 | { |
||
548 | if (isset($_SESSION['__ci_vars'][$k]) && is_int($_SESSION['__ci_vars'][$k])) |
||
549 | { |
||
550 | unset($_SESSION['__ci_vars'][$k]); |
||
551 | } |
||
552 | } |
||
553 | |||
554 | if (empty($_SESSION['__ci_vars'])) |
||
555 | { |
||
556 | unset($_SESSION['__ci_vars']); |
||
557 | } |
||
558 | } |
||
559 | |||
560 | // ------------------------------------------------------------------------ |
||
561 | |||
562 | /** |
||
563 | * __get() |
||
564 | * |
||
565 | * @param string $key 'session_id' or a session data key |
||
566 | * @return mixed |
||
567 | */ |
||
568 | public function __get($key) |
||
569 | { |
||
570 | // Note: Keep this order the same, just in case somebody wants to |
||
571 | // use 'session_id' as a session data key, for whatever reason |
||
572 | if (isset($_SESSION[$key])) |
||
573 | { |
||
574 | return $_SESSION[$key]; |
||
575 | } |
||
576 | elseif ($key === 'session_id') |
||
577 | { |
||
578 | return session_id(); |
||
579 | } |
||
580 | |||
581 | return NULL; |
||
582 | } |
||
583 | |||
584 | // ------------------------------------------------------------------------ |
||
585 | |||
586 | /** |
||
587 | * __set() |
||
588 | * |
||
589 | * @param string $key Session data key |
||
590 | * @param mixed $value Session data value |
||
591 | * @return void |
||
592 | */ |
||
593 | public function __set($key, $value) |
||
594 | { |
||
595 | $_SESSION[$key] = $value; |
||
596 | } |
||
597 | |||
598 | // ------------------------------------------------------------------------ |
||
599 | |||
600 | /** |
||
601 | * Session destroy |
||
602 | * |
||
603 | * Legacy CI_Session compatibility method |
||
604 | * |
||
605 | * @return void |
||
606 | */ |
||
607 | public function sess_destroy() |
||
608 | { |
||
609 | session_destroy(); |
||
610 | } |
||
611 | |||
612 | // ------------------------------------------------------------------------ |
||
613 | |||
614 | /** |
||
615 | * Session regenerate |
||
616 | * |
||
617 | * Legacy CI_Session compatibility method |
||
618 | * |
||
619 | * @param bool $destroy Destroy old session data flag |
||
620 | * @return void |
||
621 | */ |
||
622 | public function sess_regenerate($destroy = FALSE) |
||
623 | { |
||
624 | $_SESSION['__ci_last_regenerate'] = time(); |
||
625 | session_regenerate_id($destroy); |
||
626 | } |
||
627 | |||
628 | // ------------------------------------------------------------------------ |
||
629 | |||
630 | /** |
||
631 | * Get userdata reference |
||
632 | * |
||
633 | * Legacy CI_Session compatibility method |
||
634 | * |
||
635 | * @returns array |
||
636 | */ |
||
637 | public function &get_userdata() |
||
638 | { |
||
639 | return $_SESSION; |
||
640 | } |
||
641 | |||
642 | // ------------------------------------------------------------------------ |
||
643 | |||
644 | /** |
||
645 | * Userdata (fetch) |
||
646 | * |
||
647 | * Legacy CI_Session compatibility method |
||
648 | * |
||
649 | * @param string $key Session data key |
||
650 | * @return mixed Session data value or NULL if not found |
||
651 | */ |
||
652 | public function userdata($key = NULL) |
||
653 | { |
||
654 | if (isset($key)) |
||
655 | { |
||
656 | return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL; |
||
657 | } |
||
658 | elseif (empty($_SESSION)) |
||
659 | { |
||
660 | return array(); |
||
661 | } |
||
662 | |||
663 | $userdata = array(); |
||
664 | $_exclude = array_merge( |
||
665 | array('__ci_vars'), |
||
666 | $this->get_flash_keys(), |
||
667 | $this->get_temp_keys() |
||
668 | ); |
||
669 | |||
670 | foreach (array_keys($_SESSION) as $key) |
||
671 | { |
||
672 | if ( ! in_array($key, $_exclude, TRUE)) |
||
673 | { |
||
674 | $userdata[$key] = $_SESSION[$key]; |
||
675 | } |
||
676 | } |
||
677 | |||
678 | return $userdata; |
||
679 | } |
||
680 | |||
681 | // ------------------------------------------------------------------------ |
||
682 | |||
683 | /** |
||
684 | * Set userdata |
||
685 | * |
||
686 | * Legacy CI_Session compatibility method |
||
687 | * |
||
688 | * @param mixed $data Session data key or an associative array |
||
689 | * @param mixed $value Value to store |
||
690 | * @return void |
||
691 | */ |
||
692 | public function set_userdata($data, $value = NULL) |
||
693 | { |
||
694 | if (is_array($data)) |
||
695 | { |
||
696 | foreach ($data as $key => &$value) |
||
697 | { |
||
698 | $_SESSION[$key] = $value; |
||
699 | } |
||
700 | |||
701 | return; |
||
702 | } |
||
703 | |||
704 | $_SESSION[$data] = $value; |
||
705 | } |
||
706 | |||
707 | // ------------------------------------------------------------------------ |
||
708 | |||
709 | /** |
||
710 | * Unset userdata |
||
711 | * |
||
712 | * Legacy CI_Session compatibility method |
||
713 | * |
||
714 | * @param mixed $data Session data key(s) |
||
715 | * @return void |
||
716 | */ |
||
717 | public function unset_userdata($key) |
||
718 | { |
||
719 | if (is_array($key)) |
||
720 | { |
||
721 | foreach ($key as $k) |
||
722 | { |
||
723 | unset($_SESSION[$k]); |
||
724 | } |
||
725 | |||
726 | return; |
||
727 | } |
||
728 | |||
729 | unset($_SESSION[$key]); |
||
730 | } |
||
731 | |||
732 | // ------------------------------------------------------------------------ |
||
733 | |||
734 | /** |
||
735 | * All userdata (fetch) |
||
736 | * |
||
737 | * Legacy CI_Session compatibility method |
||
738 | * |
||
739 | * @return array $_SESSION, excluding flash data items |
||
740 | */ |
||
741 | public function all_userdata() |
||
742 | { |
||
743 | return $this->userdata(); |
||
744 | } |
||
745 | |||
746 | // ------------------------------------------------------------------------ |
||
747 | |||
748 | /** |
||
749 | * Has userdata |
||
750 | * |
||
751 | * Legacy CI_Session compatibility method |
||
752 | * |
||
753 | * @param string $key Session data key |
||
754 | * @return bool |
||
755 | */ |
||
756 | public function has_userdata($key) |
||
757 | { |
||
758 | return isset($_SESSION[$key]); |
||
759 | } |
||
760 | |||
761 | // ------------------------------------------------------------------------ |
||
762 | |||
763 | /** |
||
764 | * Flashdata (fetch) |
||
765 | * |
||
766 | * Legacy CI_Session compatibility method |
||
767 | * |
||
768 | * @param string $key Session data key |
||
769 | * @return mixed Session data value or NULL if not found |
||
770 | */ |
||
771 | View Code Duplication | public function flashdata($key = NULL) |
|
772 | { |
||
773 | if (isset($key)) |
||
774 | { |
||
775 | return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && ! is_int($_SESSION['__ci_vars'][$key])) |
||
776 | ? $_SESSION[$key] |
||
777 | : NULL; |
||
778 | } |
||
779 | |||
780 | $flashdata = array(); |
||
781 | |||
782 | if ( ! empty($_SESSION['__ci_vars'])) |
||
783 | { |
||
784 | foreach ($_SESSION['__ci_vars'] as $key => &$value) |
||
785 | { |
||
786 | is_int($value) OR $flashdata[$key] = $_SESSION[$key]; |
||
787 | } |
||
788 | } |
||
789 | |||
790 | return $flashdata; |
||
791 | } |
||
792 | |||
793 | // ------------------------------------------------------------------------ |
||
794 | |||
795 | /** |
||
796 | * Set flashdata |
||
797 | * |
||
798 | * Legacy CI_Session compatibility method |
||
799 | * |
||
800 | * @param mixed $data Session data key or an associative array |
||
801 | * @param mixed $value Value to store |
||
802 | * @return void |
||
803 | */ |
||
804 | public function set_flashdata($data, $value = NULL) |
||
805 | { |
||
806 | $this->set_userdata($data, $value); |
||
807 | $this->mark_as_flash(is_array($data) ? array_keys($data) : $data); |
||
808 | } |
||
809 | |||
810 | // ------------------------------------------------------------------------ |
||
811 | |||
812 | /** |
||
813 | * Keep flashdata |
||
814 | * |
||
815 | * Legacy CI_Session compatibility method |
||
816 | * |
||
817 | * @param mixed $key Session data key(s) |
||
818 | * @return void |
||
819 | */ |
||
820 | public function keep_flashdata($key) |
||
821 | { |
||
822 | $this->mark_as_flash($key); |
||
823 | } |
||
824 | |||
825 | // ------------------------------------------------------------------------ |
||
826 | |||
827 | /** |
||
828 | * Temp data (fetch) |
||
829 | * |
||
830 | * Legacy CI_Session compatibility method |
||
831 | * |
||
832 | * @param string $key Session data key |
||
833 | * @return mixed Session data value or NULL if not found |
||
834 | */ |
||
835 | View Code Duplication | public function tempdata($key = NULL) |
|
836 | { |
||
837 | if (isset($key)) |
||
838 | { |
||
839 | return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) && is_int($_SESSION['__ci_vars'][$key])) |
||
840 | ? $_SESSION[$key] |
||
841 | : NULL; |
||
842 | } |
||
843 | |||
844 | $tempdata = array(); |
||
845 | |||
846 | if ( ! empty($_SESSION['__ci_vars'])) |
||
847 | { |
||
848 | foreach ($_SESSION['__ci_vars'] as $key => &$value) |
||
849 | { |
||
850 | is_int($value) && $tempdata[$key] = $_SESSION[$key]; |
||
851 | } |
||
852 | } |
||
853 | |||
854 | return $tempdata; |
||
855 | } |
||
856 | |||
857 | // ------------------------------------------------------------------------ |
||
858 | |||
859 | /** |
||
860 | * Set tempdata |
||
861 | * |
||
862 | * Legacy CI_Session compatibility method |
||
863 | * |
||
864 | * @param mixed $data Session data key or an associative array of items |
||
865 | * @param mixed $value Value to store |
||
866 | * @param int $ttl Time-to-live in seconds |
||
867 | * @return void |
||
868 | */ |
||
869 | public function set_tempdata($data, $value = NULL, $ttl = 300) |
||
870 | { |
||
871 | $this->set_userdata($data, $value); |
||
872 | $this->mark_as_temp(is_array($data) ? array_keys($data) : $data, $ttl); |
||
873 | } |
||
874 | |||
875 | // ------------------------------------------------------------------------ |
||
876 | |||
877 | /** |
||
878 | * Unset tempdata |
||
879 | * |
||
880 | * Legacy CI_Session compatibility method |
||
881 | * |
||
882 | * @param mixed $data Session data key(s) |
||
883 | * @return void |
||
884 | */ |
||
885 | public function unset_tempdata($key) |
||
886 | { |
||
887 | $this->unmark_temp($key); |
||
888 | } |
||
889 | |||
890 | } |
||
891 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.