[ Index ]
 

Code source de Dotclear 1.2.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/inc/ -> session.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2004 Olivier Meunier and contributors. All rights
   5  # reserved.
   6  #
   7  # DotClear is free software; you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation; either version 2 of the License, or
  10  # (at your option) any later version.
  11  # 
  12  # DotClear is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  # 
  17  # You should have received a copy of the GNU General Public License
  18  # along with DotClear; if not, write to the Free Software
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  #
  21  # ***** END LICENSE BLOCK *****
  22  
  23  if(function_exists('ini_set'))
  24  {
  25      @ini_set('session.use_cookies','1');
  26      @ini_set('session.use_only_cookies','1');
  27      @ini_set('url_rewriter.tags','');
  28      @ini_set('session.use_trans_sid','0');
  29  }
  30  
  31  // NE PAS DECOMMENTER
  32  //@ini_set('session.use_only_cookies','0');
  33  
  34  $con = new connection(DB_USER,DB_PASS,DB_HOST,DB_DBASE);
  35  
  36  $dc_session = new dbSession($con,DB_PREFIX.'session');
  37  
  38  session_set_save_handler(
  39      array(&$dc_session, '_open'),
  40      array(&$dc_session, '_close'),
  41      array(&$dc_session, '_read'),
  42      array(&$dc_session, '_write'),
  43      array(&$dc_session, '_destroy'),
  44      array(&$dc_session, '_gc')
  45  ); 
  46  
  47  session_name(DC_SESSION_NAME);
  48  session_start();
  49  
  50  class dbSession
  51  {
  52      var $con;
  53      var $table;
  54      var $sess_ttl = '-120 minutes';
  55      
  56  	function dbSession(&$con,$table)
  57      {
  58          $this->con = $con;
  59          $this->table = $table;
  60      }
  61      
  62  	function _open($path,$name)
  63      {
  64          return true;
  65      }
  66      
  67  	function _close()
  68      {
  69          $this->_gc();
  70          return true;
  71      }
  72      
  73  	function _read($ses_id)
  74      {
  75          $strReq = 'SELECT * FROM '.$this->table.' '.
  76                  'WHERE ses_id = \''.$this->con->escapeStr($ses_id).'\' ';
  77          
  78          $rs = $this->con->select($strReq);
  79          
  80          if ($rs == false || $rs->isEmpty()) {
  81              return '';
  82          } else {
  83              return $rs->f('ses_value');
  84          }
  85      }
  86      
  87  	function _write($ses_id, $data)
  88      {
  89          $strReq = 'UPDATE '.$this->table.' SET '.
  90                  'ses_time = \''.time().'\', '.
  91                  'ses_value = \''.$this->con->escapeStr($data).'\' '.
  92                  'WHERE ses_id = \''.$this->con->escapeStr($ses_id).'\' ';
  93          
  94          if ($this->con->execute($strReq) === false) {
  95              return false;
  96          }
  97          
  98          if ($this->con->rowCount() > 0) {
  99              return true;
 100          }
 101          
 102          $strReq = 'INSERT INTO '.$this->table.' '.
 103                  ' (ses_id, ses_time, ses_start, ses_value) VALUES ('.
 104                  '\''.$this->con->escapeStr($ses_id).'\','.
 105                  '\''.time().'\','.
 106                  '\''.time().'\','.
 107                  '\''.$this->con->escapeStr($data).'\') ';
 108                  
 109          if ($this->con->execute($strReq) === false) {
 110              return false;
 111          }
 112          
 113          return true;
 114      }
 115      
 116  	function _destroy($ses_id)
 117      {
 118          $strReq = 'DELETE FROM '.$this->table.' '.
 119                  'WHERE ses_id = \''.$this->con->escapeStr($ses_id).'\' ';
 120          
 121          if ($this->con->execute($strReq) === false) {
 122              return false;
 123          } else {
 124              $this->_optimize();
 125              return true;
 126          }
 127      }
 128      
 129  	function _gc()
 130      {
 131          $ses_life = strtotime($this->sess_ttl);
 132          
 133          $strReq = 'DELETE FROM '.$this->table.' '.
 134                  'WHERE ses_time < '.$ses_life.' ';
 135          
 136          if ($this->con->execute($strReq) === false) {
 137              return false;
 138          }
 139          
 140          if ($this->con->rowCount() > 0) {
 141              $this->_optimize();
 142          }
 143          
 144          return true;
 145      }
 146      
 147  	function _optimize()
 148      {
 149          $strReq = 'OPTIMIZE TABLE '.$this->table.' ';
 150          
 151          if ($this->con->execute($strReq) === false) {
 152              return false;
 153          } else {
 154              return true;
 155          }
 156      }
 157  }
 158  ?>


Généré le : Fri Feb 23 21:40:15 2007 par Balluche grâce à PHPXref 0.7