po malu staram sie rozkminiac session handlera ktorego mam z phpclasses. Mam kilka pytań.
Po zalożaniu sesji w bazie mysql pojawia sie expire-date ta data sie jednak nie zmienia wiec czemu ma sluzyc ? (pobiera czas sesji i co z tym ?)
".(time() + $this->sessionLifetime)."
odwolanie do tego:
// get session lifetime
Potem nastepnie mama:
session_set_save_handler w tym read write open closed itp. Jak do tych funkcji odwolac sie z poziomu strony ?
bo dzieki funkcji read($session_id) moge wyczytac dane ktora mam w session-data czyli dane ktore zapisze $_SESSION['data']= 'x' np.
chciałbym bardziej zrozumieć dzialanie tego typu obslugi sesji.
Nie wiem jak je sprawdzac po stronie klienta bo w login.php tworze obiekt sesji zapisuje do niego dane ale np. na stronie zalogowany.php nie wiem jak do nich sie odwolac ?
SESSIOn handler:
<?php require_once ("class_connect_db.php"); class dbSession { function dbSession($gc_maxlifetime = "", $gc_probability = "", $gc_divisor = "") { // if $gc_maxlifetime is specified and is an integer number // set the new value } // if $gc_probability is specified and is an integer number // set the new value } // if $gc_divisor is specified and is an integer number // set the new value } // get session lifetime // register the new handler ); register_shutdown_function('session_write_close'); // start the session } /** * Deletes all data related to the session * * @return void */ function stop() { $this->regenerate_id(); } /** * Regenerates the session id. * * <b>Call this method whenever you do a privilege change!</b> * * @return void */ function regenerate_id() { // saves the old session's id // regenerates the id // this function will create a new session, with a new id and containing the data from the old session // but will not delete the old session // because the session_regenerate_id() function does not delete the old session, // we have to delete it manually $this->destroy($oldSessionID); } /** * Get the number of online users * * This is not 100% accurate. It depends on how often the garbage collector is run * * @return integer approximate number of users currently online */ function get_users_online() { // counts the rows from the database SELECT COUNT(session_id) as count FROM session_data ")); // return the number of found rows return $result["count"]; } /** * Custom open() function * * @access private */ function open($save_path, $session_name) { return true; } /** * Custom close() function * * @access private */ function close() { return true; } /** * Custom read() function * * @access private */ function read($session_id) { // reads session data associated with the session id // but only if the HTTP_USER_AGENT is the same as the one who had previously written to this session // and if session has not expired SELECT session_data FROM session_data WHERE session_id = '".$session_id."' AND http_user_agent = '".$_SERVER["HTTP_USER_AGENT"]."' AND "); // if anything was found // return found data // don't bother with the unserialization - PHP handles this automatically return $fields["session_data"]; } // if there was an error return an empty string - this HAS to be an empty string return ""; } /** * Custom write() function * * @access private */ function write($session_id, $session_data) { // first checks if there is a session with this id SELECT * FROM session_data WHERE session_id = '".$session_id."' "); // if there is // update the existing session's data // and set new expiry time UPDATE session_data SET session_data = '".$session_data."', WHERE session_id = '".$session_id."' "); // if anything happened // return true return true; } // if this session id is not in the database } else { // insert a new record INSERT INTO session_data ( session_id, http_user_agent, session_data, session_expire ) VALUES ( '".$session_id."', '".$_SERVER["HTTP_USER_AGENT"]."', '".$session_data."', ) "); // if anything happened // return an empty string return ""; } } // if something went wrong, return false return false; } /** * Custom destroy() function * * @access private */ function destroy($session_id) { // deletes the current session id from the database DELETE FROM session_data WHERE session_id = '".$session_id."' "); // if anything happened // return true return true; } // if something went wrong, return false return false; } /** * Custom gc() function (garbage collector) * * @access private */ function gc($maxlifetime) { // it deletes expired sessions from database DELETE FROM session_data WHERE "); } } ?>