[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * SessionHandler implementation for LDAP directories. 4 * 5 * Required parameters:<pre> 6 * 'foo' The foo. 7 * 8 * Optional parameters:<pre> 9 * 'hostspec' The hostname of the ldap server. 10 * 11 * $Horde: framework/SessionHandler/SessionHandler/ldap.php,v 1.2.2.2 2005/10/18 11:01:27 jan Exp $ 12 * 13 * This code is adapted from the comments at 14 * http://www.php.net/session-set-save-handler. 15 * 16 * See the enclosed file COPYING for license information (LGPL). If you 17 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 18 * 19 * @since Horde 3.1 20 * @package Horde_SessionHandler 21 */ 22 class SessionHandler_ldap extends SessionHandler { 23 24 /** 25 * Handle for the current database connection. 26 * 27 * @var resource 28 */ 29 var $_conn; 30 31 /** 32 * Open the SessionHandler backend. 33 * 34 * @param string $save_path The path to the session object. 35 * @param string $session_name The name of the session. 36 * 37 * @return boolean True on success, false otherwise. 38 */ 39 function open($save_path, $session_name) 40 { 41 $this->_conn = @ldap_connect($this->_params['hostspec'], $this->_params['port']); 42 return @ldap_bind($this->_conn, $this->_params['dn'], $this->_params['password']); 43 } 44 45 /** 46 * Close the SessionHandler backend. 47 * 48 * @return boolean True on success, false otherwise. 49 */ 50 function close() 51 { 52 return @ldap_close($this->_conn); 53 } 54 55 /** 56 * Read the data for a particular session identifier from the 57 * SessionHandler backend. 58 * 59 * @param string $id The session identifier. 60 * 61 * @return string The session data. 62 */ 63 function read($id) 64 { 65 $sr = @ldap_search($this->_conn, $this->_params['dn'], "(cn=$id)"); 66 $info = @ldap_get_entries($this->_conn, $sr); 67 if ($info['count'] > 0) { 68 return $info[0]['session'][0]; 69 } else { 70 return ''; 71 } 72 } 73 74 /** 75 * Write session data to the SessionHandler backend. 76 * 77 * @param string $id The session identifier. 78 * @param string $session_data The session data. 79 * 80 * @return boolean True on success, false otherwise. 81 */ 82 function write($id, $session_data) 83 { 84 $update = array('objectClass' => array('phpsession', 'top'), 85 'session' => $session_data); 86 $dn = "cn=$id," . $this->_params['dn']; 87 @ldap_delete($this->_conn, $dn); 88 return @ldap_add($this->_conn, $dn, $update); 89 } 90 91 /** 92 * Destroy the data for a particular session identifier in the 93 * SessionHandler backend. 94 * 95 * @param string $id The session identifier. 96 * 97 * @return boolean True on success, false otherwise. 98 */ 99 function destroy($id) 100 { 101 $dn = "cn=$id," . $this->_params['dn']; 102 return @ldap_delete($this->_conn, $dn); 103 } 104 105 /** 106 * Garbage collect stale sessions from the SessionHandler backend. 107 * 108 * @param integer $maxlifetime The maximum age of a session. 109 * 110 * @return boolean True on success, false otherwise. 111 */ 112 function gc($maxlifetime = 300) 113 { 114 $sr = @ldap_search($this->_conn, $this->_params['dn'], 115 '(objectClass=phpsession)', array('+', 'cn')); 116 $info = @ldap_get_entries($this->_conn, $sr); 117 if ($info['count'] > 0) { 118 for ($i = 0; $i < $info['count']; $i++) { 119 $id = $info[$i]['cn'][0]; 120 $dn = "cn=$id," . $this->_params['dn']; 121 $ldapstamp = $info[$i]['modifytimestamp'][0]; 122 $year = substr($ldapstamp, 0, 4); 123 $month = substr($ldapstamp, 4, 2); 124 $day = substr($ldapstamp, 6, 2); 125 $hour = substr($ldapstamp, 8, 2); 126 $minute = substr($ldapstamp, 10, 2); 127 $modified = gmmktime($hour, $minute, 0, $month, $day, $year); 128 if (time() - $modified >= $maxlifetime) { 129 @ldap_delete($this->_conn, $dn); 130 } 131 } 132 } 133 134 return true; 135 } 136 137 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |