blob: fb695dade128c096c8bd9376bb738ac818c6d9b5 [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 Andreev47a47fb2014-05-31 16:08:30 +030056 // ------------------------------------------------------------------------
57
58 /**
59 * Class constructor
60 *
61 * @param array $params Configuration parameters
62 * @return void
63 */
Andrey Andreevdfb39be2014-10-06 01:50:14 +030064 public function __construct(&$params)
Andrey Andreev47a47fb2014-05-31 16:08:30 +030065 {
Andrey Andreevdfb39be2014-10-06 01:50:14 +030066 $this->_config =& $params;
Andrey Andreev47a47fb2014-05-31 16:08:30 +030067 }
68
69 // ------------------------------------------------------------------------
70
71 protected function _cookie_destroy()
72 {
73 return setcookie(
Andrey Andreevdfb39be2014-10-06 01:50:14 +030074 $this->_config['cookie_name'],
Andrey Andreev47a47fb2014-05-31 16:08:30 +030075 NULL,
76 1,
Andrey Andreevdfb39be2014-10-06 01:50:14 +030077 $this->_config['cookie_path'],
78 $this->_config['cookie_domain'],
79 $this->_config['cookie_secure'],
80 TRUE
Andrey Andreev47a47fb2014-05-31 16:08:30 +030081 );
82 }
83
Andrey Andreev93d9fa72014-08-27 22:14:36 +030084 // ------------------------------------------------------------------------
85
86 /**
87 * Get lock
88 *
89 * A default locking mechanism via semaphores, if ext/sysvsem is available.
90 *
91 * Drivers will usually override this and only fallback to it if no other
92 * locking mechanism is available.
93 *
94 * @param string $session_id
95 * @return bool
96 */
97 protected function _get_lock($session_id)
98 {
99 if ( ! extension_loaded('sysvsem'))
100 {
101 $this->_lock = TRUE;
102 return TRUE;
103 }
104
Andrey Andreevdfb39be2014-10-06 01:50:14 +0300105 if (($this->_lock = sem_get($session_id.($this->_config['match_ip'] ? '_'.$_SERVER['REMOTE_ADDR'] : ''), 1, 0644)) === FALSE)
Andrey Andreev93d9fa72014-08-27 22:14:36 +0300106 {
107 return FALSE;
108 }
109
110 if ( ! sem_acquire($this->_lock))
111 {
112 sem_remove($this->_lock);
113 $this->_lock = FALSE;
114 return FALSE;
115 }
116
117 return TRUE;
118 }
119
120 // ------------------------------------------------------------------------
121
122 /**
123 * Release lock
124 *
125 * @return bool
126 */
127 protected function _release_lock()
128 {
129 if (extension_loaded('sysvsem') && $this->_lock)
130 {
131 sem_release($this->_lock);
132 sem_remove($this->_lock);
133 $this->_lock = FALSE;
134 }
135
136 return TRUE;
137 }
138
Andrey Andreev47a47fb2014-05-31 16:08:30 +0300139}
140
141/* End of file Session_driver.php */
142/* Location: ./system/libraries/Session/Session_driver.php */