note 34394 deleted from function.session-set-save-handler by danbrown

From: Date: Sun, 23 Jan 2011 16:21:44 +0000
Subject: note 34394 deleted from function.session-set-save-handler by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176056@lists.php.net to get a copy of this message
Note Submitter: rafael dot tz at uol dot com dot br ---- Hi people! I was wondering about a MySQL Sessions control... Here is some of my work, a little mod on some cods that I've found this far: if(!mysql_table_exists("sessions",$DB)) { $query = 'CREATE TABLE sessions ( SessionID char(255) not null, LastUpdated datetime not null, DataValue text, PRIMARY KEY ( SessionID ), INDEX ( LastUpdated ) )'; mysql_query($query); } function sessao_open($aSavaPath, $aSessionName) { global $aTime; sessao_gc( $aTime ); return True; } function sessao_close() { return True; } function sessao_read( $aKey ) { $query = "SELECT DataValue FROM sessions WHERE SessionID='$aKey'"; $busca = mysql_query($query); if(mysql_num_rows($busca) == 1) { $r = mysql_fetch_array($busca); return $r['DataValue']; } ELSE { $query = "INSERT INTO sessions (SessionID, LastUpdated, DataValue) VALUES ('$aKey', NOW(), '')"; mysql_query($query); return ""; } } function sessao_write( $aKey, $aVal ) { $aVal = addslashes( $aVal ); $query = "UPDATE sessions SET DataValue = '$aVal', LastUpdated = NOW() WHERE SessionID = '$aKey'"; mysql_query($query); return True; } function sessao_destroy( $aKey ) { $query = "DELETE FROM sessions WHERE SessionID = '$aKey'"; mysql_query($query); return True; } function sessao_gc( $aMaxLifeTime ) { $query = "DELETE FROM sessions WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(LastUpdated) > $aMaxLifeTime"; mysql_query($query); return True; } session_set_save_handler("sessao_open", "sessao_close", "sessao_read", "sessao_write", "sessao_destroy", "sessao_gc");

« previous php.notes (#176056) next »