PHP + MYSQL: Online website count statistics [code]

Source: Internet
Author: User
& Nbsp; php (as the mainstream development language) example Tutorial: program code for online website users, the backend supports MySQL (the best combination with PHP) databases. You can directly count the number of online users of the website. & Nbsp; create MySQL (

Php (as the mainstream development language)Example Tutorial: program code for the number of online users on the website. MySQL (the best combination with PHP) database is supported in the background. You can directly count the number of online users of the website.

First, create a MySQL database table (the best combination with PHP.

The following is a reference clip:
Create table tablename (
Field type (max_length) DEFAULT default_value (NOT) NULL
}

SQL statements that can be used.

The following is a reference clip:
Create table useronline (
Timestamp int (15) DEFAULT 0 not null,
Ip varchar (40) not null,
File varchar (100) not null,
Prima (the most comprehensive virtual host Management System) ry key (timestamp ),
KEY ip (ip ),
KEY file (file)
);

Next we will start to use the php (as the mainstream development language) script to first define the information of MySQL (the best combination with PHP.

The following is a reference clip:
$ Server = "localhost"; // your server
$ Db_user = "root"; // your MySQL (best combination with PHP) user name
$ Db_pass = "password"; // password for your MySQL (best combination with PHP)
$ Database = "users"; // table name

Set the statistical time (number of online users in seconds)

The following is a reference clip:
$ Timeoutseconds = 300;

The current time.

The following is a reference clip:
$ Timestamp = time ();

The complete code above:

The following is a reference clip:
$ Server = "localhost"; // your server
$ Db_user = "root"; // your MySQL (the best combination with PHP) database username
$ Db_pass = "password"; // your MySQL (the best combination with PHP) database password if any
$ Database = "users"; // the db name
$ Timeoutsecondds = 300; // timeoutseconds limit
// Get the current time
$ Timestamp = time ();
// Calculate the lowest timestamp allowed
$ Timeout = $ timestamp-$ timeoutseconds;
?>

Connect to MySQL (the best combination with PHP)

The following is a reference clip:
MySQL (the best combination with PHP) _ connect (localhost, username, password );

Variable format is also allowed.

The following is a reference clip:
MySQL (the best combination with PHP) _ connect ($ server, $ db_user, $ db_pass );

If the MySQL database (the best combination with PHP) does not have a password, you can use the following code to connect to the database (of course, we recommend that you set your own password so that at least hackers have to decrypt it)

The following is a reference clip:
MySQL (the best combination with PHP) _ connect ($ server, $ db_user );

Code for querying the database:

The following is a reference clip:
MySQL (the best combination with PHP) _ db_query (database, query );

We need to add a record as long as there is a visitor.

The following is a reference clip:
$ Insert = MySQL (the best combination with PHP) _ db_query ($

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.