Show current online users

Source: Internet
Author: User
This tutorial is of the original load. for details, refer to content from the webpage tutorial network: we can use a program to display the current data. Pay attention to two points: 1. the following code must be put into the extended name. PHP file; 2. when running code on your server, this tutorial is of the original load.

Prefix:

We can use a program to display the current data.

Note: 1. you must put the following code in a file named. PHP. 2. when running code on your server, your server must support the MYSQL database.

The code is as follows:

Put the following code in the place where you want to display information.


// EDIT THIS

$ Server = 'localhost ';

$ Db_user = 'database username ';

$ Db_pass = 'database password ';

$ Database = 'database ';

$ Timeoutseconds = 300;

// STOP EDITING

$ Timestamp = time ();

$ Timeout = $ timestamp-$ timeoutseconds;

Mysql_connect ($ server, $ db_user, $ db_pass );

$ Insert = mysql_db_query ($ database, 'Insert INTO useronline VALUES

('$ Timestamp',' $ REMOTE_ADDR ',' $ PHP_SELF ')');

If (! ($ Insert )){

Print 'useronline Insert Failed> ';

}

$ Delete = mysql_db_query ($ database, 'delete FROM useronline WHERE timestamp <$ timeout ');

If (! ($ Delete )){

Print 'useronline Delete Failed> ';

}

$ Result = mysql_db_query ($ database, 'Select DISTINCT ip FROM useronline WHERE file = '$ PHP_SELF '');

If (! ($ Result )){

Print 'useronline Select Error> ';

}

$ User = mysql_num_rows ($ result );

Mysql_close ();

If ($ user = 1 ){

Print ('$ user \ n ');

} Else {

Print ('$ user \ n ');

}

?>

Fix your username and passwords in MYSQL.

Note: Make $ half-width

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.