| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Platform 4 * @subpackage Session 5 * 6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 defined('JPATH_PLATFORM') or die; 11 12 /** 13 * Database session storage handler for PHP 14 * 15 * @package Joomla.Platform 16 * @subpackage Session 17 * @see http://www.php.net/manual/en/function.session-set-save-handler.php 18 * @since 11.1 19 */ 20 class JSessionStorageDatabase extends JSessionStorage 21 { 22 /** 23 * @var unknown No idea what this does. 24 * @since 11.1 25 */ 26 protected $_data = null; 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 * @since 11.1 37 */ 38 public function open($save_path, $session_name) 39 { 40 return true; 41 } 42 43 /** 44 * Close the SessionHandler backend. 45 * 46 * @return boolean True on success, false otherwise. 47 * 48 * @since 11.1 49 */ 50 public function close() 51 { 52 return true; 53 } 54 55 /** 56 * Read the data for a particular session identifier from the SessionHandler backend. 57 * 58 * @param string $id The session identifier. 59 * 60 * @return string The session data. 61 * 62 * @since 11.1 63 */ 64 public function read($id) 65 { 66 // Get the database connection object and verify its connected. 67 $db = JFactory::getDbo(); 68 if (!$db->connected()) 69 { 70 return false; 71 } 72 73 // Get the session data from the database table. 74 $query = $db->getQuery(true); 75 $query->select($db->quoteName('data')) 76 ->from($db->quoteName('#__session')) 77 ->where($db->quoteName('session_id') . ' = ' . $db->quote($id)); 78 79 $db->setQuery($query); 80 81 return (string) $db->loadResult(); 82 } 83 84 /** 85 * Write session data to the SessionHandler backend. 86 * 87 * @param string $id The session identifier. 88 * @param string $data The session data. 89 * 90 * @return boolean True on success, false otherwise. 91 * 92 * @since 11.1 93 */ 94 public function write($id, $data) 95 { 96 // Get the database connection object and verify its connected. 97 $db = JFactory::getDbo(); 98 if (!$db->connected()) 99 { 100 return false; 101 } 102 103 $query = $db->getQuery(true); 104 $query->update($db->quoteName('#__session')) 105 ->set($db->quoteName('data') . ' = ' . $db->quote($data)) 106 ->set($db->quoteName('time') . ' = ' . $db->quote((int) time())) 107 ->where($db->quoteName('session_id') . ' = ' . $db->quote($id)); 108 109 // Try to update the session data in the database table. 110 $db->setQuery($query); 111 if (!$db->query()) 112 { 113 return false; 114 } 115 116 if ($db->getAffectedRows()) 117 { 118 return true; 119 } 120 else 121 { 122 $query->clear(); 123 $query->insert($db->quoteName('#__session')) 124 ->columns($db->quoteName('session_id') . ', ' . $db->quoteName('data') . ', ' . $db->quoteName('time')) 125 ->values($db->quote($id) . ', ' . $db->quote($data) . ', ' . $db->quote((int) time())); 126 127 // If the session does not exist, we need to insert the session. 128 $db->setQuery($query); 129 return (boolean) $db->query(); 130 } 131 } 132 133 /** 134 * Destroy the data for a particular session identifier in the SessionHandler backend. 135 * 136 * @param string $id The session identifier. 137 * 138 * @return boolean True on success, false otherwise. 139 * 140 * @since 11.1 141 */ 142 public function destroy($id) 143 { 144 // Get the database connection object and verify its connected. 145 $db = JFactory::getDbo(); 146 if (!$db->connected()) 147 { 148 return false; 149 } 150 151 $query = $db->getQuery(true); 152 $query->delete($db->quoteName('#__session')) 153 ->where($db->quoteName('session_id') . ' = ' . $db->quote($id)); 154 155 // Remove a session from the database. 156 $db->setQuery($query); 157 158 return (boolean) $db->query(); 159 } 160 161 /** 162 * Garbage collect stale sessions from the SessionHandler backend. 163 * 164 * @param integer $lifetime The maximum age of a session. 165 * 166 * @return boolean True on success, false otherwise. 167 * 168 * @since 11.1 169 */ 170 public function gc($lifetime = 1440) 171 { 172 // Get the database connection object and verify its connected. 173 $db = JFactory::getDbo(); 174 if (!$db->connected()) 175 { 176 return false; 177 } 178 179 // Determine the timestamp threshold with which to purge old sessions. 180 $past = time() - $lifetime; 181 182 $query = $db->getQuery(true); 183 $query->delete($db->quoteName('#__session')) 184 ->where($db->quoteName('time') . ' < ' . $db->quote((int) $past)); 185 186 // Remove expired sessions from the database. 187 $db->setQuery($query); 188 189 return (boolean) $db->query(); 190 } 191 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |