blob: ad64e238a192626808def42347f615b3a3e0a939 [file] [log] [blame]
Andrey Andreev47a47fb2014-05-31 16:08:30 +03001<?php
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.2.4 or newer
6 *
7 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
19 * @package CodeIgniter
20 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
23 * @link http://codeigniter.com
24 * @since Version 3.0
25 * @filesource
26 */
27defined('BASEPATH') OR exit('No direct script access allowed');
28
29/**
30 * CodeIgniter Session Driver Class
31 *
32 * @package CodeIgniter
33 * @subpackage Libraries
34 * @category Sessions
35 * @author Andrey Andreev
36 * @link http://codeigniter.com/user_guide/libraries/sessions.html
37 */
38abstract class CI_Session_driver implements SessionHandlerInterface {
39
Andrey Andreevdfb39be2014-10-06 01:50:14 +030040 protected $_config;
Andrey Andreev47a47fb2014-05-31 16:08:30 +030041
42 /**
Andrey Andreev93d9fa72014-08-27 22:14:36 +030043 * Data fingerprint
Andrey Andreev47a47fb2014-05-31 16:08:30 +030044 *
45 * @var bool
46 */
47 protected $_fingerprint;
48
Andrey Andreev93d9fa72014-08-27 22:14:36 +030049 /**
50 * Lock placeholder
51 *
52 * @var mixed
53 */
54 protected $_lock = FALSE;
55
Andrey Andreev7474a672014-10-31 23:35:32 +020056 /**
57 * Read session ID
58 *
59 * Used to detect session_regenerate_id() calls because PHP only calls
60 * write() after regenerating the ID.
61 *
62 * @var string
63 */
64 protected $_session_id;
65
Andrey Andreev47a47fb2014-05-31 16:08:30 +030066 // ------------------------------------------------------------------------
67
68 /**
69 * Class constructor
70 *
71 * @param array $params Configuration parameters
72 * @return void
73 */
Andrey Andreevdfb39be2014-10-06 01:50:14 +030074 public function __construct(&$params)
Andrey Andreev47a47fb2014-05-31 16:08:30 +030075 {
Andrey Andreevdfb39be2014-10-06 01:50:14 +030076 $this->_config =& $params;
Andrey Andreev47a47fb2014-05-31 16:08:30 +030077 }
78
79 // ------------------------------------------------------------------------
80
81 protected function _cookie_destroy()
82 {
83 return setcookie(
Andrey Andreevdfb39be2014-10-06 01:50:14 +030084 $this->_config['cookie_name'],
Andrey Andreev47a47fb2014-05-31 16:08:30 +030085 NULL,
86 1,
Andrey Andreevdfb39be2014-10-06 01:50:14 +030087 $this->_config['cookie_path'],
88 $this->_config['cookie_domain'],
89 $this->_config['cookie_secure'],
90 TRUE
Andrey Andreev47a47fb2014-05-31 16:08:30 +030091 );
92 }
93
Andrey Andreev93d9fa72014-08-27 22:14:36 +030094 // ------------------------------------------------------------------------
95
96 /**
97 * Get lock
98 *
99 * A default locking mechanism via semaphores, if ext/sysvsem is available.
100 *
101 * Drivers will usually override this and only fallback to it if no other
102 * locking mechanism is available.
103 *
104 * @param string $session_id
105 * @return bool
106 */
107 protected function _get_lock($session_id)
108 {
109 if ( ! extension_loaded('sysvsem'))
110 {
111 $this->_lock = TRUE;
112 return TRUE;
113 }
114
Andrey Andreevdfb39be2014-10-06 01:50:14 +0300115 if (($this->_lock = sem_get($session_id.($this->_config['match_ip'] ? '_'.$_SERVER['REMOTE_ADDR'] : ''), 1, 0644)) === FALSE)
Andrey Andreev93d9fa72014-08-27 22:14:36 +0300116 {
117 return FALSE;
118 }
119
120 if ( ! sem_acquire($this->_lock))
121 {
122 sem_remove($this->_lock);
123 $this->_lock = FALSE;
124 return FALSE;
125 }
126
127 return TRUE;
128 }
129
130 // ------------------------------------------------------------------------
131
132 /**
133 * Release lock
134 *
135 * @return bool
136 */
137 protected function _release_lock()
138 {
139 if (extension_loaded('sysvsem') && $this->_lock)
140 {
141 sem_release($this->_lock);
142 sem_remove($this->_lock);
143 $this->_lock = FALSE;
144 }
145
146 return TRUE;
147 }
148
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300149}
150
151/* End of file Session_driver.php */
152/* Location: ./system/libraries/Session/Session_driver.php */