/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// DB Managed Sessions using PHP and MySQL. // Written by: Greg Donald <[email protected]> // $Id: session.php 6 2005-12-26 01:22:57Z destiney $ // MySQL database connection parameters: $GLOBALS[ 'dbhost' ] = 'localhost'; $GLOBALS[ 'dbuser' ] = 'root'; $GLOBALS[ 'dbpasswd' ] = 'changeme'; $GLOBALS[ 'dbname' ] = 'dbsessions'; // Session lifetime $GLOBALS[ 'online_expire' ] = 900; // Default sessions table: $GLOBALS[ 'tb_sessions' ] = 'sessions'; // Use transparent sessions: /////////////////////////////////////////////////////////////////////// // Below here should not require any changes $GLOBALS[ 'sdbh' ] = ''; function sess_open( $save_path, $session_name ) { $GLOBALS[ 'dbuser' ], $GLOBALS[ 'dbpasswd' ] ) ){ } { } return true; } function sess_close() { } function sess_read( $key ) { $sql = " SELECT `data` FROM `" . $GLOBALS[ 'tb_sessions' ] . "` WHERE `id` = '$key' AND `expire` > UNIX_TIMESTAMP() "; { } return ''; } function sess_write( $key, $val ) { $sql = " REPLACE INTO `" . $GLOBALS[ 'tb_sessions' ] . "` ( `id`, `data`, `expire` ) VALUES ( '$key', '$value', UNIX_TIMESTAMP() + " . $GLOBALS[ 'online_expire' ] . " ) "; } function sess_destroy( $key ) { $sql = " DELETE FROM `" . $GLOBALS[ 'tb_sessions' ] . "` WHERE `id` = '$key' "; } function sess_gc() { $sql = " DELETE FROM `" . $GLOBALS[ 'tb_sessions' ] . "` WHERE `expire` < UNIX_TIMESTAMP() - " . $GLOBALS[ 'online_expire' ] . " "; } 'sess_close', 'sess_read', 'sess_write', 'sess_destroy', 'sess_gc' );