Ways to Judge online users

Source: Internet
Author: User
Tags array count current time header require stmt variable trim
Online solved yesterday's problem: the results of the table changed, as follows:
CREATE table Tb_user (--User table
N_userid Number (5) Not NULL--User ID
V_nickname VARCHAR2 (Ten) not NULL,--Nickname
V_pwd VARCHAR2 (Ten) not NULL,--Password
V_truename VARCHAR2 (20),--Name
Primary Key (N_userid)
)
CREATE TABLE Tb_onlineuser (--Online users
N_onlineuserid Number (5) Not NULL,--Online User ID
D_logintime Number (16),--Login time in seconds
N_onlineid Number (5),--associated with Onlineusercount.
Primary Key (N_onlineid)
)
/
CREATE TABLE Tb_onlineusercount (--Online user statistics
N_onlineid Number (5) is not NULL--System ID
N_onlineuserid Number (5) Not NULL,--Online User ID
D_logindate Date--dates of landing
D_logintime Number (16),--Login time in seconds
D_overdate date,--end dates
D_overtime Number (16),--End time
Primary Key (N_onlineid)
)
/

* *---loginselectnew.php---this procedure is the landing check procedure----* *
?
Session_Start ();
* Thinking: First user login, to determine whether there is the user, to determine whether the password passed, otherwise return parameters for special treatment. (Landing unsuccessful)
After successful landing, if the user is not online (generally not online, special case if he uses another machine to open the browser to land again, then he may be online),
First, the session variable registration, to obtain the corresponding conditions to 1 statistics and 2. Insert data in the online table. Enter the landing page.
If the user is online: Get the system ID of the online user first, because it is useful to back up the user when they leave. The online user is then deleted. Then the backup of the user's departure time.
*/
Session_register ("Objsnickname");
Require (' oracle8conn.php ');
$name =trim ($name);
$pwd =trim ($PWD);
Ob_start (); Buffered output
$stmtNick = Ociparse ($conn, "SELECT count (*) Countnickname from Tb_user where v_nickname= ' $name '");
Ociexecute ($stmtNick);
while (Ocifetchinto ($stmtNick,& $arrN)) {
if ($arrN [0]==0) {
Header ("Location:Logintest.php?") Msg=1 ");
}else{
User name passed
Unset ($arrNickName); Undo a 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) {
Header ("Location:Logintest.php?") Msg=2 ");
}else{//Password passed
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)) {
$intOnlineUserID = $arrU [0];
}//while_over
If the user repeatedly logs on through another browser, resolve the following
$stmOnlineFlag =ociparse ($conn, "SELECT COUNT (*) from Tb_onlineuser where n_onlineuserid= ' $intOnlineUserID '");
Ociexecute ($stmOnlineFlag);
while (Ocifetchinto ($stmOnlineFlag,& $arronlineFlag, oci_num)) {
if ($arronlineFlag [0]!=0) {//indicates already online
First get the online user associated system ID
$stmtSysID = Ociparse ($conn, "select N_onlineid from Tb_onlineuser where n_onlineuserid= ' $intOnlineUserID '");
Ociexecute ($stmtSysID);
while (Ocifetchinto ($stmtSysID,& $arrSysID, oci_num)) {
$SysID = $arrSysID [0];
}//while_over//To kick out the user after finding out
$stmt = Ociparse ($conn, "delete from Tb_onlineuser where n_onlineuserid= ' $intOnlineUserID ')";
Ociexecute ($stmt);
Print "Delete succeeded"; 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_onlineusercount set d_overdate= $DatLoginDate, D_overtime= $tmpTime where n_ Onlineid= ' $SysID ');/condition is the associated system ID
Ociexecute ($stmtUserCount);
Print "added successfully to the statistics table. ";
}//ENDIF//No online normal registration
$objsNickName = $name; Register Session variable
Unset ($ARRPWD); Undo a temporary array
Srand (Double) microtime () *1000000000);
$intOnlineID = rand (); Take a System ID number
$DatLoginDate = Date ("y-m-d"); Get the system date into the online table.
$DatLogintime = time (); Take system time
$DatLoginDate = "To_date ('" $DatLoginDate. "', ' yy/mm/dd ')";
$stmt = Ociparse ($conn, insert into Tb_onlineuser (N_onlineuserid,d_logintime,n_onlineid) 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"); Successful Landing!
}//whileover
}//end if
}//while_over
}//end if
}//while_over

?>
<?ob_end_flush ();? >
/*-------checksession-----Check the Refresh process---* *
?
/*30 minutes Refresh Program
First count the number of users online, if there is no online users, the system to ensure that a system designated users. The reason that the system users are always online is to ensure the execution of the refresh program
If the logon user session does not exist, it means that the user is offline. Count the time.
*/
Session_Start ();
Require (' oracle8conn.php ');
Print $objsNickName;
?>
?
$NowDate = Date ("y-m-d");
$NowDate = "To_date ('" $NowDate. "', ' yy/mm/dd ')";
$NowTime = time ();
Statistics online number. 30-minute Update
$stmtCount = Ociparse ($conn, select COUNT (*) from Tb_onlineuser);
Ociexecute ($stmtCount);
while (Ocifetchinto ($stmtCount,& $arrCountUser)) {
$CountUser = $arrCountUser [0];
}
Print "Current number of online:". $CountUser. " <br> ";
Judge Online no?
if ($CountUser ==0) {
Print "No one online!" Special treatment! ";
}else{
$stmtOnlineUser = Ociparse ($conn, "Select N_onlineuserid,d_logintime,n_onlineid from Tb_onlineuser");
Ociexecute ($stmtOnlineUser);
$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 it is stored in a two-dimensional array, double loops.
For ($a =0 $a <1; $a + +) {//inner loop find time once.
Note that the double loop is to take the array value
$arrTest [$b][0] represents the user ID
$arrTest [$b][1] indicates the time of landing
$arrTest [$b][1] associated system ID
if (Ceil ($NowTime-$arrTest [$b][1]) >300) {//If the current time differs from the old time of a record by more than 30 minutes.
if ($objsNickName = = "") {//If this user session does not exist, indicates that it has exited.
Delete.
$temGlid = $arrTest [$b][2]; Associated System ID
$temuserid = $arrTest [$b][0]; User ID
$stmt = Ociparse ($conn, "delete from tb_onlineuser where $intOnlineID = ' $temGlid ' and n_onlineuserid= ' $temuserid ');
Print "Delete from tb_onlineuser where $intOnlineID = ' $temGlid ' and n_onlineuserid= ' $temuserid '";
Ociexecute ($stmt);
Print "Delete succeeded";
Add to statistics
$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 the associated system ID
Ociexecute ($stmtUserCount);
Print "added successfully 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 succeeded";
Print $tmpTime;
}
}else{
Print session_id ();
Print "System time:". $NowTime. " <br> ";
Print "Old Time in Database:". $arrTest [$b][1]. " <br> ";
Print "User id:". $arrTest [$b][0]. " <br> ";
Print "Time difference:". Ceil ($NowTime-$arrTest [$b][1])/60. " <br> ";
}
}
}

* * If you want to observe the statistics 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; Difference
If you want to count the time that a specified user is online (when the user is offline)
Select D_logintime,d_overtime from Tb_onlineusercount where n_onlineuserid= ' $USERID '; Difference
*/

?>

Thank you for your help! :_)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.