A simple free php counter

Source: Internet
Author: User

This is managed using a database.
Recommended Database
Create table count (
Userid varchar (20) not null,
Count varchar (20) not null,
Ip varchar (20) not null
);
Application page


Counter application


If (! Isset ($ submit ))
{
?>


}
Else
{
$ Mysql_db = mysql_connect ("localhost", "root", "") or die ("database connection failed ");
Mysql_select_db ("footboy", $ mysql_db) or die ("failed to select a database table ");
$ SQL = "select * from count where userid = $ userid ";
$ Result = mysql_query ($ SQL );
$ Num = mysql_num_rows ($ result );
$ Ip = getenv ("remote_addr ");


If ($ num | $ userid = "") // determines whether the ID exists and whether the input is correct
{
Printf ("% s already exists or the input is blank", $ userid );
Print ("return ");
Mysql_close ();
}
Else
{
$ Insert = "insert into count VALUES ($ userid, 1, $ ip)"; // meets the conditions and records data
Mysql_query ($ insert );
Print ("$ userid, congratulations, you have returned a successful application
");
Print ("can you use the following code to apply a http://footboy.host.wayall.com/count/count.php? Userid = $ userid ");
Mysql_close ();
}
}
?>


Application page
$ Mysql_db = mysql_connect ("localhost", "root", ""); // connect to the database
Mysql_select_db ("footboy", $ mysql_db );
$ SQL = "select * from count where userid = $ userid"; // Database Query
$ Result = mysql_query ($ SQL );
$ SQL _row = mysql_fetch_array ($ result );
$ Num = mysql_num_rows ($ result); // determines whether the user has applied
$ Count = $ SQL _row [count]; // retrieves counter data
// Format the data into five digits
$ Count_len = strlen ($ count );
For ($ I = 0; $ I <5-$ count_len; $ I ++)
{$ Count = "0". $ count ;}
// Obtain the browsing user IP address to prevent repeated refreshing
$ Ip = getenv ("remote_addr ");
If ($ num)
{
If ($ ip! = $ SQL _row [ip])
{
$ SQL _row [count] ++; // The start count output when the condition is met
Printf ("You are browsing this site at % s
", $ Count );
Mysql_query ("update count set count = $ SQL _row [count], ip = $ ip where userid = $ userid"); // store data
Mysql_close ();
}
Else
{
Printf ("You are browsing this site at % s
", $ Count );
Print ("welcome to our site again ");
}
}
Else
Printf ("% s user does not exist, please apply first", $ userid );
Mysql_close ();
?>

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.