Typically, session is saved in a temporary file, but if you save it in the database, you will bring us a lot of benefits, such as statistics. Do not say nonsense, see the program:
PHPINCLUDE ("db_mysql.inc");
Function open ($ save_path, $ session_name) {Global $ DB, $ Remote_addr; $ db-> query ("delete from sessions where sessionlast
Function close ()
Return True;}
Function Read ($ ID) {Global $ db; if (! $ db-> query ("SELECT SESSIONID from> Query (" SELECT SESSIONID AD ') || $ dB-> Num_ROWS () <= 0) Return False; $ SQL = "Select sessionData from sessions where sessionid = '$ ID'"; $ db-> query ($ sql); list ($ sess_data) = $ dB-> fetch_row (); return ($ sess_data);}
Function Write ($ ID, $ sess_data) {global $ db; if (! $ db-> query ("Select sessionid from sessions where sessionID = '$ ID') || $ db-> num_rows () <= 0) Return false; if ($ db-> query ("Update sessions setsessionData = '$ sess_data', sessionLast = now () where sessionId = '$ ID'") Return True; Else Return False;}
Function Destroy ($ ID) {Global $ DB; $ DB-> Query ("Delete from sessions where sessionid = '$ ID'");}
Function GC ($ Maxlifetime) {Return True;}
Session_set_save_handler ("Open", "Close", "Read", "WRITE", "Destroy", "GC"); session_start ();
?> Note: Data table: sessionscreate table sessions (sessionid varchar (50) Not null, sessionname varchar (50) Not null, sessionData blob, sessionlast datetime default '0000-00-00 00:00:00' Not Null, Primary Key SESSIONID);