• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

include/inc.db_session_handler.php

Go to the documentation of this file.
00001 <?php
00011 /*
00012     +-----------------------------------------------------------------------------+
00013     | ILIAS open source                                                           |
00014     +-----------------------------------------------------------------------------+
00015     | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00016     |                                                                             |
00017     | This program is free software; you can redistribute it and/or               |
00018     | modify it under the terms of the GNU General Public License                 |
00019     | as published by the Free Software Foundation; either version 2              |
00020     | of the License, or (at your option) any later version.                      |
00021     |                                                                             |
00022     | This program is distributed in the hope that it will be useful,             |
00023     | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00024     | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00025     | GNU General Public License for more details.                                |
00026     |                                                                             |
00027     | You should have received a copy of the GNU General Public License           |
00028     | along with this program; if not, write to the Free Software                 |
00029     | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
00030     +-----------------------------------------------------------------------------+
00031 */
00032 
00033 
00034 /*
00035 * open session, normally a db connection would be opened here, but
00036 * we use the standard ilias db connection, so nothing must be done here
00037 *
00038 * @param        string          $save_pathDSN   information about how to access the database, format:
00039 *                                                                               dbtype(dbsyntax)://username:password@protocol+hostspec/database
00040 *                                                                               eg. mysql://phpsessmgr:topsecret@db.example.com/sessiondb
00041 * @param        string          $name                   session name [PHPSESSID]
00042 */
00043 function db_session_open($save_path, $name)
00044 {
00045         return true;
00046 }
00047 
00053 function db_session_close()
00054 {
00055         return true;
00056 }    
00057 
00058 /*
00059 * Reads data of the session identified by $session_id and returns it as a
00060 * serialised string. If there is no session with this ID an empty string is
00061 * returned
00062 *
00063 * @param        integer         $session_id             session id
00064 */
00065 function db_session_read($session_id)
00066 {
00067         global $ilDB;
00068 
00069         $q = "SELECT data FROM usr_session WHERE session_id = '".addslashes($session_id)."'";
00070         $r = $ilDB->query($q);
00071         $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00072 
00073         return $data["data"];
00074 }
00075 
00082 function db_session_write($session_id, $data)
00083 {
00084         global $pear_session_db,$ilDB;
00085 
00086         //var_dump("<pre>",session_decode($data),"</pre>");exit;
00087         $expires = time() + ini_get("session.gc_maxlifetime");
00088         $q = "REPLACE INTO usr_session (session_id, expires, data, ctime,user_id) ".
00089                  "VALUES('".ilUtil::prepareDBString($session_id)."','".$expires."','".ilUtil::prepareDBString($data).
00090                  "','".time()."','".$_SESSION["AccountId"]."')";
00091         $ilDB->query($q);        
00092 
00093         return true;
00094 }
00095 
00101 function db_session_destroy($session_id)
00102 {
00103         global $ilDB;
00104 
00105         $q = "DELETE FROM usr_session WHERE session_id = '".addslashes($session_id)."'";
00106         $ilDB->query($q);
00107   
00108         return true;
00109 }
00110 
00111 
00117 function db_session_gc($gc_maxlifetime)
00118 {
00119         global $pear_session_db,$ilDB;
00120 
00121         $q = "DELETE FROM usr_session WHERE expires < ".time();
00122         $ilDB->query($q);
00123         
00124         return true;
00125 }
00126 
00127 
00128 /*
00129 * register callback functions
00130 * session.save_handler must be 'user' or safe mode off to succeed
00131 */
00132 function db_set_save_handler()
00133 {
00134         // register save handler functions
00135         if (ini_get("session.save_handler") == "user")
00136         {
00137                 session_set_save_handler(
00138                         "db_session_open",
00139                         "db_session_close",
00140                         "db_session_read",
00141                         "db_session_write",
00142                         "db_session_destroy",
00143                         "db_session_gc");
00144                         
00145                         return true;
00146         }
00147         
00148         return false;
00149 }
00150 
00151 // needs to be done to assure that $ilDB exists,
00152 // when db_session_write is called
00153 register_shutdown_function("session_write_close");
00154 
00155 ?>

Generated on Fri Dec 13 2013 13:52:11 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1