1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| <?php $gb_DBname="db_myBBS"; $gb_DBuser="root"; $gb_DBpass="23928484"; $gb_DBHOSTname="localhost"; $SESS_DBH=""; $SESS_LIFE=get_cfg_var("session.gc_maxlifetime"); function sess_open($save_path,$session_name){ global $gb_DBHOSTname,$gb_DBname,$gb_DBuser,$gb_DBpass,$SESS_DBH; if(!$SESS_DBH=mysql_pconnect($gb_DBHOSTname,$gb_DBuser,$gb_DBpass)){ echo "<li>MySql Error:".mysql_error()."<li>"; die(); } if(!mysql_select_db($gb_DBname,$SESS_DBH)){ echo "<li>MySql Error:".mysql_error()."<li>"; die(); } return true; } function sess_close(){ return true; } function sess_read($key){ global $SESS_DBH,$SESS_LIFE; $qry="select value from db_session where sesskey = '$key' and expiry > ".time(); $qid=mysql_query($qry,$SESS_DBH); if(list($value)=mysql_fetch_row($qid)){ return $value; } return false; } function sess_write($key,$val){ global $SESS_DBH,$SESS_LIFE; $expiry=time()+$SESS_LIFE; $value=$val; $qry="insert into db_session values('$key',$expiry,'$value')"; $qid=mysql_query($qry,$SESS_DBH); if(!$qid){ $qry="update db_session set expiry=$expiry, value='$value' where sesskey='$key' and expiry >".time(); $qid=mysql_query($qry,$SESS_DBH); } return $qid; } function sess_destroy($key){ global $SESS_DBH; $qry="delete from db_session where sesskey = '$key'"; $qid=mysql_query($qry,$SESS_DBH); return $qid; } function sess_gc($maxlifetime){ global $SESS_DBH; $qry="delete from db_session where expiry < ".time(); $qid=mysql_query($qry,$SESS_DBH); return mysql_affected_rows($SESS_DBH); } session_module_name(); session_set_save_handler("sess_open","sess_close","sess_read","sess_write","sess_destroy","sess_gc"); ?>
|