At the beginning of this article, the author assumes that the reader has been able to write a user's login certification program.
----------------------------------------------------------
Registers can complete the total number of times to access the Web page, but do not know the dynamic record of access in a period of time, the following describes how to write a different period of time to dynamically display the number of traffic methods.
To record the traffic, first set up a database in MySQL, let's call this database line, and create a data table named line, the table field is "User name (name varchar (20)), Time (DateTime)". Of course, readers can also add fields to the data table as needed.
Set up a good database, you can start the design process, now to clear up the idea, to show the traffic, of course, the database must have a record, I have assumed that the reader has the ability to write a user login program, so to add records to the database can be added to the login program login.php:
Pay the present time first: $time =date (' y-m-d h:i:s ');
mysql_select_db (line);
mysql_query ("INSERT into line (Name,time) VALUES (' $name ', ' $time ')");
OK, now every login user has a record in the database, the following is to complete the user online display program line.php:
Mysql_connect ("local", "", "");
mysql_select_db (line);
$result =mysql_query ("SELECT * from line");
$num =mysql_numrows ($result);
if (!empty ($num)) {
echo "
http://www.bkjia.com/PHPjc/445180.html www.bkjia.com true http://www.bkjia.com/PHPjc/445180.html techarticle at the beginning of this article, the author assumes that the reader has been able to write a user's login authentication program.----------------------------------------------------------register to complete access to Web pages ...
"; echo "Number of online now: $num"; echo " |
"; for ($i =0; $i < $num; $i + +) {$name =mysql_result ($result, $i, "name"), echo "
Users: $name |
"; } } ? > The above program has been able to show all the number of online users and user names, of course, this program is not perfect. If one of the users logs out, the database should not have this user's record so, the logout program assumes that the logout.php is added with the delete function: Mysql_ select_db (line); mysql_query ("Delete from line where name= ' $name '"); At this time a basic user online functionality has been completed, and then continue to add code within the line.php to make the function more perfect, first we have to specify how long the user has not continued to browse line.php when the user is considered to have left, here given a limit of 5 minutes, In other words, the program will display the first 5 minutes from the beginning of the user situation, so must be set within the line.php a time to inform the program from this time to execute, and then implement the program execution when the database recorded in the time less than the current time of more than 5 minutes of all records deleted, so that any user in the execution When line.php, you can see all the online users within 5 minutes, and the following database statement is required to complete this function: