Solved yesterday's question: The result is changed, as follows:
CREATE TABLE TB_USER (- user table
N_Userid Number (5) Not Null, - User ID
V_nickname varchar2 (10) Not null, - nickname
V_pwd varchar2 (10) Not null, - password
V_truename varcha2 (20), - name
PRIMARY key (n_userid)
)
Create Table TB_ONLINEUSER (- Online User
N_OnlineUserid Number (5) Not Null, - Online User ID
D_Logintime Number (16), - Landing time in seconds
N_onlineid Number (5), - associated with OnlineUserCount.
PRIMARY key (n_onlineid)
)
/
Create Table TB_OnlineUsercount (- Online User Statistics Table
N_Onlineid Number (5) Not Null, - System ID Number
N_OnlineUserid Number (5) Not Null, - Online User ID
D_Logindate Date, - Landing Date
D_Logintime Number (16), - Landing time in seconds
D_Overdate Date, - End Date
D_OVERTIME NUMBER (16), - End Time
PRIMARY key (n_onlineid)
)
/
/*---Loginselectnew.php--- This program is the login check program ---- * /
session_start ();
/ * Idea: First, the user logs in and determines whether the user has the user, and determines whether the password is passed, otherwise the return parameter is specially processed. (Landing is not successful)
After the login is successful, if the user is not online (generally not online, special circumstances if he uses another machine to open the browser again to log in, then he may be online),
First, session variables are registered, and the corresponding conditions are obtained to the statistics table and 2. Insert the data in the online table. Enter the login page.
If the user is online: the system ID of the online user is first obtained, because it is useful when the user is backing. The online user is then deleted. Then, the backup of the user leaves time.
* /
Session_register ("objsnickname");
Require ('Oracle8conn.php');
$ Name = Trim ($ name);
$ PWD = TRIM ($ PWD);
Ob_start (); // buffer output
$ STMTNICK = OCIPARSE ($ conn, "Select Count (*) countnickname from tb_user where v_nickname = '$ name');
Ociexecute ($ STMTNICK);
While (OCIFETCHINTO ($ StmTnick, & $ ARRN) {
IF ($ arrn [0] == 0) Else {
// username
Unset ($ arrnickname); // Undo temporary array
$ STMTPWD = OCIPARSE ($ conn "select count (*) CountPwd from tb_user where v_pwd = '$ pwd' and v_nickname = '$ name'); OCIEXECUTE ($ STMTPWD);
While (OCIFETCHINTO ($ Stmtpwd, & $ Arrp, OCI_Num) {
IF ($ arrp [0] == 0) ELSE {// password pass
/ / Remove the user ID number
$ stmtuid = ociparse ($ conn, "select n_userid from tb_user where v_nickname = '$ name');
Ociexecute ($ STMTUID);
While (OCIFETCHINTO ($ Stmtuid, & $ Arru, OCI_NUM) // While_Over
// If the user repeatedly logs into another browser,
$ stmonlineflag = ocipival ($ conn, "select count (*) from tb_onlineuser where n_onlineuserid = '$ inlineuserid'");
Ociexecute ($ stmonlineflag);
While (OCIFETCHINTO ($ Stmonlineflag, & $ ArronlineFlag, OCI_NUM) {
IF ($ arronlineflag [0]! = 0) {// indicates already online
// Take the online user associated system ID
$ stmtsysid = OCIPARSE ($ conn, "SELECT N_OONLINEID from TB_ONLINEUSER WHERE N_OONLINEUSERID = '$ INTONLINEUSERID');
Ociexecute ($ STMTSYSID);
While (OCIFETCHINTO ($ Stmtsysid, & $ Arrsysid, OCI_NUM) // while_over // After finding the user
$ STMT = OCIPARSE ($ conn, "delete from tb_onlineuser where n_onlineuse = '$ intonLineuserid');
OCIEXECUTE ($ STMT);
Print "Delete Success"; // Finally make a record backup
$ TMPTIME = Time (); // End Time
$ Datlogindate = DATE ("Y-m-D"); // End date
$ Datlogindate = "to_date ('". $ Datlogindate. "', 'Yy / mm / dd')
$ stmtusercount = ociparse ($ conn, "Update TB_OONLineUserCount Set D_Overdate = $ DATLOGINDATE, D_OVERTIME = $ TMPTIME WHERE N_OONLINEID = '$ sysid'); // Condition is associated with the system ID
Ociexecute ($ stmtusercount);
Print "Add success to the statistics table."
} // Endif // Not online registration $ objsnickname = $ name; // Register session variable
Unset ($ arrpwd); // Undo temporary array
SRAND (Double) microtime () * 1000000000);
$ INTONLINEID = rand (); // Take a system ID number
$ DATLOGINDATE = DATE ("Y-m-D"); // Get the system date to deploy in the Online table.
$ Datlogintime = Time (); // Take the system time
$ Datlogindate = "to_date ('". $ Datlogindate. "', 'Yy / mm / dd')
$ STMT = OCIPARSE ($ Conn, "INSERT INTO TB_ONLINEUSER (N_Onlineuserid, D_Logintime, N_OnOnEid) Values ($ INTONLINEUSERID, $ DATLOGINTIME, $ INTONLINEID");
OCIEXECUTE ($ STMT);
$ StmtC = OCIParse ($ conn, "insert into TB_OnlineUserCount (N_OnlineID, N_OnlineUserId, D_LoginDate, D_LoginTime) values ($ intOnlineID, $ intOnlineUserID, $ DatLoginDate, $ DatLogintime)");
OCIEXECUTE ($ STMTC);
Header ("Location: Index.php"); // Successfully landed!
} // Whileover
} // end if
} // While_Over
} // end if
} // While_Over
?>
OB_END_FLUSH ();?>
/ * ------- Checksession ----- Check the refresh program --- * /
/ * 30 minutes refresh program
First count the number of users, if there is no online user, the system must assure a system to specify the user. The reason why the user is online when the system is user time is to ensure the execution of the refresh program.
If the login user session does not exist, it means that the user is offline. Statistics time.
* /
session_start ();
Require ('Oracle8conn.php');
Print $ ObjsnickName;
?>
$ NOWTIME = Time ();
// Statistics online number. 30 minutes update
$ STMTCOUNT = Ocipival ($ conn, "select count (*) from tb_onlineuser");
Ociexecute ($ STMTCOUNT);
While (OCIFETCHINTO ($ Stmtcount, & $ Arrcountuser) {
$ Countuser = $ arrcountuser [0];
}
"The current online number is:" $ countuser. "
"; // Is it judged?
IF ($ countuser == 0) {
Print "No one online! Special treatment!";
} else {
$ stmtonlineuser = ociparse ($ conn, "select n_onlineuserid, d_logintime, n_onlineid from tb_onlineuser");
Ociexecute ($ stmtonlineuse);
$ arrtest = array ();
While (OCIFETCHINTO ($ Stmtonlineuser, & $ arruser [])) {
$ Arrtest = $ arruser;
}
$ J = SIZEOF ($ Arrtest);
IF ($ j> 0) {
$ I = SIZEOF ($ Arrtest [0]);
}
}
For ($ b = 0; $ b <$ j; $ b ) {// Because the two-dimensional array is deposited, the double loop.
FOR ($ A = 0; $ a <1; $ A ) {// Loan to find time.
// Note that the dual cycle is to take an array value.
// $ arteest [$ b] [0] Represents user ID
// $ arteest [$ b] [1] indicates the time to log in
// $ arteest [$ b] [1] associated system ID
IF (CEIL ($ B] [1]) / 60)> 300) {// If the current time is more than 30 minutes of the old time of a record.
IF ($ ObjsnickName == ") {// If this user session does not exist, it indicates that you have exited.
// Delete.
$ TEMGLID = $ Arrtest [$ b] [2]; // Related System ID
$ Temuserid = $ Arrtest [$ b] [0]; // User ID
$ STMT = OCIPARSE ($ conn "delete from tb_onlineuser where $ intonlineid = '$ TEMGLID' and N_OONLINEUSERID = '$ Temuserid');
Print "delete from tb_onlineuser where $ intonlineid = '$ temglid' and n_onlineuserid = '$ temuserid'
OCIEXECUTE ($ STMT);
Print "Delete Success";
// Add to the statistics table
$ TMPTIME = Time (); // End Time
$ Datlogindate = DATE ("Y-m-D"); // End date
$ Datlogindate = "to_date ('". $ Datlogindate. "', 'Yy / mm / dd')
$ STMTUSERCOUNT = OCIPARSE ($ conn, "Update TB_OnlineUserCount Set D_Overdate = $ DATLOGINDATE, D_OVERTIME = $ TMPTIME WHERE N_ONLINEID = '$ TEMGLID'"); // Condition is associated with the system ID
Ociexecute ($ stmtusercount);
Print "Add success to the statistics table."
} else {
$ tmptime = time (); // get temporary user time $ Temuserid = $ Arrtest [$ b] [0];
$ STMT = OCIPARSE ($ conn, "Update TB_ONLINEUSER SET D_Logintime = $ TMPTIME WHERE N_ONLINEUSERID = '$ Temuserid');
OCIEXECUTE ($ STMT);
Print "Update success";
Print $ TMPTIME;
}
} else {
PRINT session_id ();
Print "System Time:" $ NOWTIME. "
";
Print "Database in the old time:" $ arteest [$ b] [1]. "
";
Print "User ID:". $ Arrtest [$ B] [0]. "
";
PRINT "Division time:". CEIL ($ NOWTIME- $ Arrtest [$ B] [1]) / 60). "
";
}
}
}
/ * If you want to catch a statistics table and online table user time (when the user is not offline)
SELECT A.D_Logintime, B.D_Logintime from TB_ONLINEUSER A, TB_ONLINEUSERCOUNT B
WHERE A.N_ONLINEID = B.N_ONLINEID; phase difference
If you want to count the user's online time (when the user is offline)
SELECT D_Logintime, D_OVertime from TB_ONLINEUSERCOUNT WHERE N_OONLINEUSERID = '$ UserId';
* /
?>