& 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 ($ |