[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

/lib/Horde/SessionHandler/ -> dbm.php (source)

   1  <?php
   2  /**
   3   * SessionHandler:: implementation for DBM files.
   4   * NOTE: The PHP DBM functions are deprecated.
   5   *
   6   * No additional configuration parameters needed.
   7   *
   8   * $Horde: framework/SessionHandler/SessionHandler/dbm.php,v 1.9.12.7 2006/01/01 21:28:34 jan Exp $
   9   *
  10   * Copyright 2002-2006 Chuck Hagenbuch <chuck@horde.org>
  11   *
  12   * See the enclosed file COPYING for license information (LGPL). If you
  13   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  14   *
  15   * @author  Chuck Hagenbuch <chuck@horde.org>
  16   * @since   Horde 3.0
  17   * @package Horde_SessionHandler
  18   */
  19  class SessionHandler_dbm extends SessionHandler {
  20  
  21      /**
  22       * Our pointer to the DBM file, if open.
  23       *
  24       * @var resource
  25       */
  26      var $_dbm;
  27  
  28      /**
  29       * Open the SessionHandler backend.
  30       *
  31       * @param string $save_path     The path to the session object.
  32       * @param string $session_name  The name of the session.
  33       *
  34       * @return boolean  True on success, false otherwise.
  35       */
  36      function open($save_path, $session_name)
  37      {
  38          $this->_dbm = @dbmopen("$save_path/$session_name", 'c');
  39          return $this->_dbm;
  40      }
  41  
  42      /**
  43       * Close the SessionHandler backend.
  44       *
  45       * @return boolean  True on success, false otherwise.
  46       */
  47      function close()
  48      {
  49          return @dbmclose($this->_dbm);
  50      }
  51  
  52      /**
  53       * Read the data for a particular session identifier from the
  54       * SessionHandler backend.
  55       *
  56       * @param string $id  The session identifier.
  57       *
  58       * @return string  The session data.
  59       */
  60      function read($id)
  61      {
  62          if ($data = dbmfetch($this->_dbm, $id)) {
  63              return base64_decode(substr($data, strpos($data, '|') + 1));
  64          } else {
  65              return '';
  66          }
  67      }
  68  
  69      /**
  70       * Write session data to the SessionHandler backend.
  71       *
  72       * @param string $id            The session identifier.
  73       * @param string $session_data  The session data.
  74       *
  75       * @return boolean  True on success, false otherwise.
  76       */
  77      function write($id, $session_data)
  78      {
  79          return @dbmreplace($this->_dbm, $id, time() . '|' . base64_encode($session_data));
  80      }
  81  
  82      /**
  83       * Destroy the data for a particular session identifier in the
  84       * SessionHandler backend.
  85       *
  86       * @param string $id  The session identifier.
  87       *
  88       * @return boolean  True on success, false otherwise.
  89       */
  90      function destroy($id)
  91      {
  92          if (!(@dbmdelete($this->_dbm, $id))) {
  93              Horde::logMessage('Failed to delete session (id = ' . $id . ')', __FILE__, __LINE__, PEAR_LOG_ERR);
  94              return false;
  95          }
  96  
  97          return true;
  98      }
  99  
 100      /**
 101       * Garbage collect stale sessions from the SessionHandler backend.
 102       *
 103       * @param integer $maxlifetime  The maximum age of a session.
 104       *
 105       * @return boolean  True on success, false otherwise.
 106       */
 107      function gc($maxlifetime = 300)
 108      {
 109          $expired = time() - $maxlifetime;
 110          $id = dbmfirstkey($this->_dbm);
 111  
 112          while ($id) {
 113              if ($data = dbmfetch($this->_dbm, $id)) {
 114                  $age = substr($tmp, 0, strpos($data, '|'));
 115                  if ($expired > $age) {
 116                      $this->destroy($id);
 117                  }
 118              }
 119  
 120              $id = dbmnextkey($this->_dbm, $id);
 121          }
 122  
 123          return true;
 124      }
 125  
 126  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7