Elgg  Version 1.9
DatabaseSessionHandler.php
Go to the documentation of this file.
1 <?php
2 
12 
14  protected $db;
15 
21  public function __construct(Elgg_Database $db) {
22  $this->db = $db;
23  }
24 
28  public function open($save_path, $name) {
29  return true;
30  }
31 
35  public function read($session_id) {
36 
37  $id = sanitize_string($session_id);
38  $query = "SELECT * FROM {$this->db->getTablePrefix()}users_sessions WHERE session='$id'";
39  $result = $this->db->getDataRow($query);
40  if ($result) {
41  return (string) $result->data;
42  } else {
43  return false;
44  }
45  }
46 
50  public function write($session_id, $session_data) {
51  $id = sanitize_string($session_id);
52  $time = time();
53  $sess_data_sanitised = sanitize_string($session_data);
54 
55  $query = "REPLACE INTO {$this->db->getTablePrefix()}users_sessions
56  (session, ts, data) VALUES
57  ('$id', '$time', '$sess_data_sanitised')";
58 
59  if ($this->db->insertData($query) !== false) {
60  return true;
61  } else {
62  return false;
63  }
64  }
65 
69  public function close() {
70  return true;
71  }
72 
76  public function destroy($session_id) {
77 
78  $id = sanitize_string($session_id);
79  $query = "DELETE FROM {$this->db->getTablePrefix()}users_sessions WHERE session='$id'";
80  return (bool) $this->db->deleteData($query);
81  }
82 
86  public function gc($max_lifetime) {
87 
88  $life = time() - $max_lifetime;
89  $query = "DELETE FROM {$this->db->getTablePrefix()}users_sessions WHERE ts < '$life'";
90  return (bool) $this->db->deleteData($query);
91  }
92 
93 }
open($save_path, $name)
Re-initialize existing session, or creates a new one.Called when a session starts or when session_sta...
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
__construct(Elgg_Database $db)
Constructor.
write($session_id, $session_data)
Writes the session data to the session storage.The session id. The encoded session data...
sanitize_string($string)
Sanitize a string for database use.
Definition: database.php:140
close()
Closes the current session.boolean
gc($max_lifetime)
Cleans up expired sessions.Sessions not updated for max_lifetime seconds are removed. boolean
read($session_id)
Reads the session data from the session storage, and returns the results.The session id...
destroy($session_id)
Destroys a session.The session id. boolean
if(!$collection_name) $id
Definition: add.php:17