Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 1 | <?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 | */ |
| 27 | defined('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 | */ |
| 38 | abstract class CI_Session_driver implements SessionHandlerInterface { |
| 39 | |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 40 | protected $_config; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 41 | |
| 42 | /** |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 43 | * Data fingerprint |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 44 | * |
| 45 | * @var bool |
| 46 | */ |
| 47 | protected $_fingerprint; |
| 48 | |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 49 | /** |
| 50 | * Lock placeholder |
| 51 | * |
| 52 | * @var mixed |
| 53 | */ |
| 54 | protected $_lock = FALSE; |
| 55 | |
Andrey Andreev | 7474a67 | 2014-10-31 23:35:32 +0200 | [diff] [blame^] | 56 | /** |
| 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 Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 66 | // ------------------------------------------------------------------------ |
| 67 | |
| 68 | /** |
| 69 | * Class constructor |
| 70 | * |
| 71 | * @param array $params Configuration parameters |
| 72 | * @return void |
| 73 | */ |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 74 | public function __construct(&$params) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 75 | { |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 76 | $this->_config =& $params; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // ------------------------------------------------------------------------ |
| 80 | |
| 81 | protected function _cookie_destroy() |
| 82 | { |
| 83 | return setcookie( |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 84 | $this->_config['cookie_name'], |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 85 | NULL, |
| 86 | 1, |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 87 | $this->_config['cookie_path'], |
| 88 | $this->_config['cookie_domain'], |
| 89 | $this->_config['cookie_secure'], |
| 90 | TRUE |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 91 | ); |
| 92 | } |
| 93 | |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 94 | // ------------------------------------------------------------------------ |
| 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 Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 115 | if (($this->_lock = sem_get($session_id.($this->_config['match_ip'] ? '_'.$_SERVER['REMOTE_ADDR'] : ''), 1, 0644)) === FALSE) |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 116 | { |
| 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 Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* End of file Session_driver.php */ |
| 152 | /* Location: ./system/libraries/Session/Session_driver.php */ |