Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved lock to before read

Signed-off-by: dchill42 <dchill42@gmail.com>
  • Loading branch information...
commit ae9e7d6e59e133bfa75e09eb6b5de6821ac7ef3b 1 parent b7dbef5
@dchill42 authored
Showing with 28 additions and 33 deletions.
  1. +28 −33 system/libraries/Session/drivers/Session_cookie.php
View
61 system/libraries/Session/drivers/Session_cookie.php
@@ -194,7 +194,7 @@ class CI_Session_cookie extends CI_Session_driver {
*
* @var bool
*/
- protected $data_dirty = FALSE;
+ protected $data_dirty = FALSE;
/**
* Initialize session driver object
@@ -240,6 +240,33 @@ protected function initialize()
'in your config file.');
}
+ // Lock if enabled
+ if ($this->sess_lock_cookie === TRUE)
+ {
+ // Create tempfile name with session id
+ $file = rtrim(str_replace('\\', '/', sys_get_temp_dir()), '/').
+ '/sess_cookie_lock_'.$this->userdata['session_id'];
+
+ // Try up to 3 times to lock the file
+ $handle = FALSE;
+ for ($i = 0; $i < 3; ++$i)
+ {
+ // Open (create) file for write, which will incur flock() until
+ // the end of the request
+ $handle = fopen($file, 'c');
+ if ($handle !== FALSE)
+ {
+ break;
+ }
+ }
+
+ // Make sure we got it
+ if ($handle === FALSE)
+ {
+ show_error('Unable to lock session cookie');
+ }
+ }
+
// Load the string helper so we can use the strip_slashes() function
$this->CI->load->helper('string');
@@ -302,40 +329,8 @@ public function sess_save()
$this->data_dirty = TRUE;
}
- // Lock if enabled
- $handle = FALSE;
- if ($this->sess_lock_cookie === TRUE)
- {
- // Create tempfile name with session id
- $file = rtrim(str_replace('\\', '/', sys_get_temp_dir()), '/').
- '/sess_cookie_lock_'.$this->userdata['session_id'];
-
- // Try up to 3 times to lock the file
- for ($i = 0; $i < 3; ++$i)
- {
- // Open (create) file for write, which will incur flock() until we close it
- $handle = fopen($file, 'c');
- if ($handle !== FALSE)
- {
- break;
- }
- }
-
- // Make sure we got it
- if ($handle === FALSE)
- {
- show_error('Unable to lock session cookie for update');
- }
- }
-
// Write the cookie
$this->_set_cookie();
-
- // Unlock if locked
- if ($handle !== FALSE)
- {
- fclose($handle);
- }
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.