PHP + MYSQL provides a [code] for counting the number of online website users. Php (as the mainstream development language) example Tutorial: the program code of the number of online users of the website. MySQL (the best combination with PHP) databases are supported in the background. You can directly calculate the website status
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 ($Http://www.bkjia.com/PHPjc/509160.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/509160.htmlTechArticlephp (as the current mainstream development language) example Tutorial: the number of online website program code, background MySQL (and PHP with the best combination) database support. You can directly calculate the website when... |