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 | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 56 | // ------------------------------------------------------------------------ |
| 57 | |
| 58 | /** |
| 59 | * Class constructor |
| 60 | * |
| 61 | * @param array $params Configuration parameters |
| 62 | * @return void |
| 63 | */ |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame^] | 64 | public function __construct(&$params) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 65 | { |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame^] | 66 | $this->_config =& $params; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | // ------------------------------------------------------------------------ |
| 70 | |
| 71 | protected function _cookie_destroy() |
| 72 | { |
| 73 | return setcookie( |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame^] | 74 | $this->_config['cookie_name'], |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 75 | NULL, |
| 76 | 1, |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame^] | 77 | $this->_config['cookie_path'], |
| 78 | $this->_config['cookie_domain'], |
| 79 | $this->_config['cookie_secure'], |
| 80 | TRUE |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 81 | ); |
| 82 | } |
| 83 | |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 84 | // ------------------------------------------------------------------------ |
| 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 Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame^] | 105 | 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] | 106 | { |
| 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 Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /* End of file Session_driver.php */ |
| 142 | /* Location: ./system/libraries/Session/Session_driver.php */ |