ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSessionDBHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Authentication/classes/class.ilSession.php");
6 
15 {
16  /*
17  * register callback functions
18  * session.save_handler must be 'user' or safe mode off to succeed
19  */
20  public function setSaveHandler()
21  {
22  // register save handler functions
23  if (session_status() === PHP_SESSION_ACTIVE) {
24  return true;
25  }
26 
27  if (ini_get("session.save_handler") == "user" || version_compare(PHP_VERSION, '7.2.0', '>=')) {
28  session_set_save_handler(
29  array($this, "open"),
30  array($this, "close"),
31  array($this, "read"),
32  array($this, "write"),
33  array($this, "destroy"),
34  array($this, "gc")
35  );
36 
37  return true;
38  }
39 
40  return false;
41  }
42 
43  /*
44  * open session, normally a db connection would be opened here, but
45  * we use the standard ilias db connection, so nothing must be done here
46  *
47  * @param string $save_pathDSN information about how to access the database, format:
48  * dbtype(dbsyntax)://username:password@protocol+hostspec/database
49  * eg. mysql://phpsessmgr:topsecret@db.example.com/sessiondb
50  * @param string $name session name [PHPSESSID]
51  */
52  public function open($save_path, $name)
53  {
54  return true;
55  }
56 
62  public function close()
63  {
64  return true;
65  }
66 
67  /*
68  * Reads data of the session identified by $session_id and returns it as a
69  * serialised string. If there is no session with this ID an empty string is
70  * returned
71  *
72  * @param integer $session_id session id
73  */
74  public function read($session_id)
75  {
76  return ilSession::_getData($session_id);
77  }
78 
85  public function write($session_id, $data)
86  {
87  $cwd = getcwd();
88  chdir(IL_INITIAL_WD);
89  include_once("./Services/Authentication/classes/class.ilSession.php");
90  $r = ilSession::_writeData($session_id, $data);
91  // see bug http://www.ilias.de/mantis/view.php?id=18000
92  //chdir($cwd);
93  return $r;
94  }
95 
101  public function destroy($session_id)
102  {
103  return ilSession::_destroy($session_id);
104  }
105 
111  public function gc($gc_maxlifetime)
112  {
114  }
115 }
116 
117 // needs to be done to assure that $ilDB exists,
118 // when db_session_write is called
119 register_shutdown_function("session_write_close");
static _destroy($a_session_id, $a_closing_context=null, $a_expired_at=null)
Destroy session.
gc($gc_maxlifetime)
removes sessions that weren&#39;t updated for more than gc_maxlifetime seconds
Database Session Handling.
destroy($session_id)
destroy session
static _destroyExpiredSessions()
Destroy expired sessions.
$r
Definition: example_031.php:79
const IL_INITIAL_WD
Definition: error.php:4
static _getData($a_session_id)
Get session data from table.
static _writeData($a_session_id, $a_data)
Write session data.
write($session_id, $data)
Writes serialized session data to the database.
$data
Definition: bench.php:6