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 ();
?>