This is managed with a database.
Recommended database
CREATE TABLE Count (
UserID varchar () is not NULL,
Count varchar (not NULL),
IP varchar (NOT NULL)
);
Application Page
<title>Counter Request</title>
if (!isset ($submit))
{
?>
}
Else
{
$mysql _db=mysql_connect ("localhost", "root", "") or Die ("database connection failed");
mysql_select_db ("Footboy", $mysql _db) or Die ("Database Select Table Failed");
$sql = "SELECT * from Count where userid= $userid";
$result =mysql_query ($sql);
$num =mysql_num_rows ($result);
$ip =getenv ("remote_addr");
if ($num | | $userid = = "")//determine if the ID exists, and whether the input is correct
{
printf ("%s already exists or is entered as empty", $userid);
Print ("return");
Mysql_close ();
}
Else
{
$insert = "INSERT INTO Count VALUES ($userid, 1, $ip)";//meet conditions, record data
mysql_query ($insert);
Print ("$userid, congratulations on your application for a successful return
");
Print ("You can apply http://footboy.host.wayall.com/count/count.php?userid= $userid with the following code");
Mysql_close ();
}
}
?>
Application Page
$mysql _db=mysql_connect ("localhost", "root", "");//Connect to 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);//Determine if the user has applied
$count = $sql _row[count];//out counter data
Format the data as 5-bit
$count _len=strlen ($count);
for ($i =0; $i <5-$count _len; $i + +)
{$count = "0". $count;}
Get browse User IP to prevent duplicate refreshes
$ip =getenv ("remote_addr");
if ($num)
{
if ($ip! = $sql _row[ip])
{
$sql _row[count]++;//condition satisfies start count output
printf ("You are the first%s to browse this site
", $count);
mysql_query ("Update count set count= $sql _row[count],ip= $ip where userid= $userid");//Deposit data
Mysql_close ();
}
Else
{
printf ("You are the first%s to browse this site
", $count);
Print ("Welcome to this site again");
}
}
Else
printf ("%s user not present, please apply First", $userid);
Mysql_close ();
?>
http://www.bkjia.com/PHPjc/532167.html www.bkjia.com true http://www.bkjia.com/PHPjc/532167.html techarticle This is managed with a database. Recommended database CREATE TABLE count (userid varchar) NOT NULL, count varchar (+) NOT NULL, IP varchar (+) not NULL); Application Page Counter Application ...