Advertisement
Guest User

Untitled

a guest
Nov 20th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  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.     public function _open(){
  27.         return ($this->db)? true : false;
  28.     }
  29.    
  30.     public function _close(){
  31.         return true;
  32.     }
  33.    
  34.     public function _read($id){
  35.         $this->db->select_table('session')->where(array('sess_id' => $id))->limit(1)->select();
  36.         if($this->db->STH->rowCount() > 0){
  37.             return $this->db->fetch[0]['data'];
  38.         }
  39.         else{
  40.             $access = time();
  41.             $this->db->select_table('session')->insert(array('sess_id' => $id,'access' => $access));
  42.         }
  43.         return '';
  44.     }
  45.    
  46.     public function _write($id, $data){
  47.         $access = time();
  48.        
  49.         $this->db->select_table('session')->where(array('sess_id' => $id))->update(array('access' => $access, 'data' => $data));
  50.         return ($this->db->STH->rowCount() > 0)? true : false;
  51.     }
  52.    
  53.     public function _destroy($id){
  54.         $this->db->select_table('session')->where(array('sess_id' => $id))->delete();
  55.         return ($this->db->STH->rowCount() > 0)? true : false;
  56.     }
  57.    
  58.     public function _gc($max){
  59.         $old = time() - $max;
  60.        
  61.         $this->db->select_table('session')->where(array('access' => $max), 'AND', '<')->delete();
  62.         return ($this->db->STH->rowCount() > 0)? true : false;
  63.     }
  64.    
  65.     ...
  66.     Other Methods
  67.     ...
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement