Show current number online

Source: Internet
Author: User

Introduced:

We can use the program to display the current data.

Focus on two points: 1. The following code must be placed in a file with a. php extension, 2. Your server must support the MySQL database when running code on your server.

The code is as follows:

The following code is placed where you want to display the information.

<?php

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 ("$usern");

} else {

Print ("$usern");

}

?>

Finally, modify your username and passwords in MySQL

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.