Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Component\Session;
- class Session{
- private $db;
- public function __construct(array $config = array()){
- $this->db = \App::service('db');
- if(session_id() == ''){
- if($config['sess_handler']){
- session_set_save_handler(
- array($this, "_open"),
- array($this, "_close"),
- array($this, "_read"),
- array($this, "_write"),
- array($this, "_destroy"),
- array($this, "_gc")
- );
- }
- ini set...
- ini_set('session.gc_maxlifetime',259200);
- ini_set('session.cookie_lifetime',259200);
- ini_set...
- session_start();
- }
- public function _open(){
- return ($this->db)? true : false;
- }
- public function _close(){
- return true;
- }
- public function _read($id){
- $this->db->select_table('session')->where(array('sess_id' => $id))->limit(1)->select();
- if($this->db->STH->rowCount() > 0){
- return $this->db->fetch[0]['data'];
- }
- else{
- $access = time();
- $this->db->select_table('session')->insert(array('sess_id' => $id,'access' => $access));
- }
- return '';
- }
- public function _write($id, $data){
- $access = time();
- $this->db->select_table('session')->where(array('sess_id' => $id))->update(array('access' => $access, 'data' => $data));
- return ($this->db->STH->rowCount() > 0)? true : false;
- }
- public function _destroy($id){
- $this->db->select_table('session')->where(array('sess_id' => $id))->delete();
- return ($this->db->STH->rowCount() > 0)? true : false;
- }
- public function _gc($max){
- $old = time() - $max;
- $this->db->select_table('session')->where(array('access' => $max), 'AND', '<')->delete();
- return ($this->db->STH->rowCount() > 0)? true : false;
- }
- ...
- Other Methods
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement