Principle:
1. The first user browses to a page.
2. The server program reads the number of times the page has been browsed from the database or file.
3. Add the number of times to the store and return it to the first user.
4. Second user browses to a page.
5. The server program reads the number of times the page has been browsed from the database or file.
6. Add one more storage and send it back to the second user.
Functions to understand:
fopen () Open File
FileSize () Get File size
Fseek () Move file pointer
Fgets () Gets the contents of the file pointer.
Fputs () writes the string as the location of the file pointer
Fclose () Close file
File_exists () to determine whether a file exists
EXEC () Execute external program
The simplest registers:
<title> Visitor Counter Prototypes </title>
<body>
<?php
/*
(c) 1998 David W. Bettis
Here is the copyright information
*/
$counterFile = "Counter.txt";
#这里是定义记数器文件
function Displaycounter ($counterFile) {
$fp = fopen ($counterFile, "RW");
#打开文件, using read and Write methods
$num = Fgets ($fp, 5);
#取得当前数字
$num + 1;
#加1
Print "You are the first." $num "." "a boring person";
EXEC ("Rm-rf $counterFile");
EXEC ("echo $num > $counterFile");
#偷懒的方式哦, do not use fputs write
}
if (!file_exists ($counterFile)) {
EXEC ("Echo 0 > $counterFile");
#如果记数器文件不存在, create it and set the content to 0
PHP Register Database version:
Using SQL registers, you build your table first.
CREATE TABLE counter
(
counter int NOT NULL,
Idint NOT NULL
)
INSERT into counter (counter,id) VALUE (0,1)
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.