PHP Counter Design and Implementation page 1/2

Source: Internet
Author: User

Ben Program There are 4 counters.
Index. php is a common counter that shows the total number of times and the number of people who come to the site. It is not waterproof when you click a few times.
Index1.php is also a waterproof counter that shows the number of times and the number of people who come to the site. It is waterproof and can be added once every 5 seconds.
Index2.php is a waterproof counter that shows the total number of times and the number of people who come to the site. The number of times points is added several times, which is waterproof and can be added once in 2 seconds.
Indexa. PHP is a common, waterproof, and graphic counter in three-in-one. We can see the total number of times and the number of people who came to the site, which is waterproof and graphic.

Key statement:
Waterproof: $ SQL = "select count (*) from 'counter _ 1' where user = '$ user' and time_to_sec (now ()-'time ') <5 and IP = '$ remote_addr '";
Graphic counters: For ($ I = 0; $ I <strlen ($ row [0]); $ I ++)
{
$ Digit = substr ($ row [0], $ I, 1 );

$ Pic. = " ";
}

<?

// ------ [Basic settings] -------
$ Mysql_server_name = "localhost ";
$ Mysql_username = "root ";
$ Mysql_password = "512783 ";
$ Mysql_database = "jishuqi ";
//-------

// Prepare your SQL
$ SQL = "insert into 'counter _ 1' ('user', 'IP', 'time') values ('$ user',' $ ip ', now ());";

$ Conn = mysql_connect ($ mysql_server_name, $ mysql_username, $ mysql_password );
Mysql_select_db ($ mysql_database, $ conn );
$ Result = mysql_query ($ SQL );
// $ Id = mysql_insert_id ();
Mysql_close ($ conn );

// Establish a connection ------ pass (server address, user name, user password)
$ Conn = mysql_connect ($ mysql_server_name, $ mysql_username, $ mysql_password );

// Prepare your SQL syntax
$ SQL = "select count (*) from 'counter _ 1 '";

// Query (or execution, select)
$ Result = mysql_db_query ($ mysql_database, $ SQL, $ conn );

// Capture the query result -->
$ Row1 = mysql_fetch_row ($ result );

// Print the array of all columns of the data
// Print_r ($ row1 );

// Clear query results
Mysql_free_result ($ result );

// Establish a connection ------ pass (server address, user name, user password)
$ Conn = mysql_connect ($ mysql_server_name, $ mysql_username, $ mysql_password );

// Prepare your SQL syntax
$ SQL = "select count (*) from 'counter _ 1 'where user =' $ user '";

// Query (or execution, select)
$ Result = mysql_db_query ($ mysql_database, $ SQL, $ conn );

// Capture the query result -->
$ Row2 = mysql_fetch_row ($ result );

// Print the array of all columns of the data
// Print_r ($ row2 );

// Clear query results
Mysql_free_result ($ result );
?>





3 counters


under Maple Forest




total People visited This website


total People come Website




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.