Include "class/config. inc. php"; // include the configuration file
$ Db = new db;
$ Db-> db_connect (); // connect to the database
$ User = new user; // Initialization
$ Session = new session;
// Start the session
Session_start ();
// Delete expired users in the session table (that is, non-online users). This file is always called to ensure that all users are currently online.
$ Curtime = time ();
$ Con = "lastactivity <$ curtime ";
$ Session-> del ($ con );
// Online users must constantly update the lastactivity time in the session table and reset the user's COOKIES.
If ($ HTTP_SESSION_VARS ["online"] = "on") {// $ _ SESSION ["online"] is also available here
$ Userid = $ HTTP_SESSION_VARS ["userid"]; // Obtain the userid of the current online user
$ Ipaddress = substr ($ REMOTE_ADDR, 0, 50 );
$ Lastactivity = time () + 3600; // update the Last activity time. If the page is not transferred within one hour, the user is considered offline and deleted.
$ Session-> update ($ userid, $ ipaddress, $ lastactivity );
} Else {
// If you have not logged on, go directly to the logon page.
$ Firstpage = "logon. php ";
Header ("Location: $ firstpage ");
Exit;
}
Insert ($ userid, $ ipaddress, $ lastactivity) inserts successfully logged on users into the table
Update ($ userid, $ ipaddress, $ lastactivity) updates the Last activity time of an online user.
Del ($ con) deletes a qualified user and uses it to clear offline users
Get_from_condition ($ con) returns the set of records that meet the query conditions.
If ($ hiddenField = "0") {// The Test form has not been submitted.
$ Con = "username = '$ username' and userpwd =' $ userpwd '";
$ Result = $ user-> get_from_condition ($ con );
If ($ user-> counter = 1 ){
If (! Session_is_registered ("online") {// check whether it has been registered
Session_register ("online"); // register a new variable as the session variable.
}
If (! Session_is_registered ("ccauser ")){
Session_register ("ccauser ");
}
If (! Session_is_registered ("userid ")){
Session_register ("userid ");
}
$ Ccauser = $ username; // assign a value to the session variable
$ Online = "on"; // This variable is used in global. php to update lastactivity.
$ Userid = $ user-> userid;
$ Ipaddress = substr ($ REMOTE_ADDR, 0, 50 );
$ Lastactivity = time () + 3600;
$ Con = "userid = $ userid ";
$ Session-> get_from_condition ($ con );
// Determine whether a session exists. You may log on to a different machine twice.
If ($ session-> counter = 1 ){
$ Session-> update ($ userid, $ ipaddress, $ lastactivity); // If yes, update
} Else {
$ Session-> insert ($ userid, $ ipaddress, $ lastactivity); // If not, insert
}
// Set COOKIES on the client
SetCookie ("ccauser", $ username, time () + 3600 );
Header ("Location: test. php"); // guide the test page
}
}
?>
If ($ HTTP_SESSION_VARS ["online"] = ") {// You can check whether you have logged on to the server.
?>
// The following is the logon form.
Name:
Password:
} Else {
Echo ":". $ HTTP_COOKIE_VARS ["ccauser"]. "you have logged on"; // If you have logged on, a prompt is displayed.
$ Str ="
Withdraw from the community ";
Echo $ str;
}
?>
Include "global. php"; // include the global. php file.
$ StrWelcome = "welcome". $ _ SESSION ['ccauser']."
";
Echo $ strWelcome; // display welcome information
$ Str = "current online user:
==============================
";
$ Con = "1 = 1 ";
// Put forward that all the records in the session table are the current online user and the visitor is not included
$ Result = $ session-> get_from_condition ($ con );
While ($ row = mysql_fetch_array ($ result )){
$ Con1 = "userid = $ row [userid]";
$ User-> get_from_condition ($ con1 );
$ Str. = $ user-> username ."";
}
Echo $ str;
?>
Withdraw from the community