Skip to content

Instantly share code, notes, and snippets.

@ClaraLeigh
Created September 25, 2018 05:43
Show Gist options
  • Save ClaraLeigh/eb4af54e565fabb886923ba613172802 to your computer and use it in GitHub Desktop.
Save ClaraLeigh/eb4af54e565fabb886923ba613172802 to your computer and use it in GitHub Desktop.
OpenCart 1.5 Non-Blocking Sessions
<?php
class Session {
public $data = array();
public function __construct() {
$this->data = new SessionData();
}
function getId() {
return $this->data->getId();
}
}
class SessionData implements ArrayAccess {
private $data = array();
protected $session_id;
protected function openSession()
{
if (!session_id()) {
ini_set('session.use_only_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
ini_set('session.cookie_httponly', 'On');
session_set_cookie_params(0, '/');
if (!empty($this->session_id)) {
ini_set('session.cache_limiter', null);
}
session_start();
} else {
if (!empty($this->session_id)) {
ini_set('session.cache_limiter', null);
}
session_start();
}
$this->data =& $_SESSION;
$this->session_id = session_id();
}
protected function closeSession()
{
session_write_close();
}
public function offsetSet($offset, $value) {
$this->openSession();
if (is_null($offset)) {
$this->data[] = $value;
} else {
$this->data[$offset] = $value;
}
$this->closeSession();
}
public function offsetExists($offset) {
$this->openSession();
$bool = isset($this->data[$offset]);
$this->closeSession();
return $bool;
}
public function offsetUnset($offset) {
$this->openSession();
unset($this->data[$offset]);
$this->closeSession();
}
public function offsetGet($offset) {
$this->openSession();
$bool = isset($this->data[$offset]) ? $this->data[$offset] : null;
$this->closeSession();
return $bool;
}
function getId() {
return $this->session_id;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment