phpPoA2
[ class tree: phpPoA2 ] [ index: phpPoA2 ] [ all elements ]

Source for file SessionDB.php

Documentation is available at SessionDB.php

  1. <?php
  2. /**
  3.  * @copyright Copyright 2005-2010 RedIRIS, http://www.rediris.es/
  4.  *
  5.  *  This file is part of phpPoA2.
  6.  *  
  7.  *  phpPoA2 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 3 of the License, or
  10.  *  (at your option) any later version.
  11.  *  
  12.  *  phpPoA2 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 phpPoA2. If not, see <http://www.gnu.org/licenses/>.
  19.  *
  20.  * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  21.  * @version 2.0
  22.  * @author Candido Rodriguez <candido.rodriguez@rediris.es>
  23.  * @filesource
  24.  */
  25.  
  26. /**
  27.  * Session database backend.
  28.  * WARNING: please note that PHP only allows one session at a time, so using
  29.  * this backend will break any applications that make use of sessions beneath.
  30.  * @package phpPoA2
  31.  * @subpackage GenericDatabaseHandlers
  32.  */
  33. class SessionDB extends GenericDB {
  34.  
  35.     protected $session_name = "session_db";
  36.  
  37.     public function open({
  38.         return function_exists("session_start");
  39.     }
  40.  
  41.     public function check($key{
  42.         if (!isset($_SESSION)) {
  43.             session_start();
  44.         }
  45.         if (array_key_exists($this->session_name$_SESSION)) {
  46.             $data $_SESSION[$this->session_name];
  47.             return array_key_exists($key$data);
  48.         }
  49.         return false;
  50.     }
  51.  
  52.     public function replace($key$value{
  53.         if (!isset($_SESSION)) {
  54.             session_start();
  55.         }
  56.         if (!array_key_exists($this->session_name$_SESSION)) {
  57.             $_SESSION[$this->session_namearray();
  58.         }
  59.         $_SESSION[$this->session_name][$key$value;
  60.         return true;
  61.     }
  62.  
  63.     public function fetch($key{
  64.         if (!isset($_SESSION)) {
  65.             session_start();
  66.         }
  67.         if (array_key_exists($this->session_name$_SESSION)) {
  68.             return $_SESSION[$this->session_name][$key];
  69.         }
  70.         return false;
  71.     }
  72.  
  73.     public function fetch_all({
  74.         if (!isset($_SESSION)) {
  75.             session_start();
  76.         }
  77.         if (array_key_exists($this->session_name$_SESSION)) {
  78.             return $_SESSION[$this->session_name];
  79.         }
  80.         return false;
  81.     }
  82.  
  83.     public function delete($key{
  84.         if (!isset($_SESSION)) {
  85.             session_start();
  86.         }
  87.         if (array_key_exists($this->session_name$_SESSION)) {
  88.             if (array_key_exists($key$_SESSION[$this->session_name])) {
  89.                 unset($_SESSION[$this->session_name][$key]);
  90.                 return true;
  91.             }
  92.             else {
  93.                 return false;
  94.             }
  95.         }
  96.         return false;
  97.     }
  98.  
  99.     public function close({
  100.         return true;
  101.     }
  102. }
  103.  
  104. ?>

Documentation generated on Wed, 13 Oct 2010 15:06:25 +0200 by phpDocumentor 1.4.3