Advertisement
Guest User

Untitled

a guest
Nov 20th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. namespace Component\Session;
  3.  
  4. class Session{
  5.    
  6.     private $db;
  7.    
  8.     public function __construct(array $config = array()){
  9.         $this->db = \App::service('db');
  10.         if(session_id() == ''){
  11.             if($config['sess_handler']){
  12.                 session_set_save_handler(
  13.                     array($this, "_open"),
  14.                     array($this, "_close"),
  15.                     array($this, "_read"),
  16.                     array($this, "_write"),
  17.                     array($this, "_destroy"),
  18.                     array($this, "_gc")
  19.                 );
  20.             }
  21.         ini set...
  22.         ini_set('session.gc_maxlifetime',259200);
  23.         ini_set('session.cookie_lifetime',259200);
  24.         ini_set...
  25.  
  26.     session_start();
  27.     }
  28.  
  29.     public function _open(){
  30.         return ($this->db)? true : false;
  31.     }
  32.    
  33.     public function _close(){
  34.         return true;
  35.     }
  36.    
  37.     public function _read($id){
  38.         $this->db->select_table('session')->where(array('sess_id' => $id))->limit(1)->select();
  39.         if($this->db->STH->rowCount() > 0){
  40.             return $this->db->fetch[0]['data'];
  41.         }
  42.         else{
  43.             $access = time();
  44.             $this->db->select_table('session')->insert(array('sess_id' => $id,'access' => $access));
  45.         }
  46.         return '';
  47.     }
  48.    
  49.     public function _write($id, $data){
  50.         $access = time();
  51.        
  52.         $this->db->select_table('session')->where(array('sess_id' => $id))->update(array('access' => $access, 'data' => $data));
  53.         return ($this->db->STH->rowCount() > 0)? true : false;
  54.     }
  55.    
  56.     public function _destroy($id){
  57.         $this->db->select_table('session')->where(array('sess_id' => $id))->delete();
  58.         return ($this->db->STH->rowCount() > 0)? true : false;
  59.     }
  60.    
  61.     public function _gc($max){
  62.         $old = time() - $max;
  63.        
  64.         $this->db->select_table('session')->where(array('access' => $max), 'AND', '<')->delete();
  65.         return ($this->db->STH->rowCount() > 0)? true : false;
  66.     }
  67.    
  68.     ...
  69.     Other Methods
  70.     ...
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement