The simplest PHP program-the stenographer. Principle: 1. the first user browses a page. 2. the number of times the server program reads the page from the database or file. 3. store the number of times and send it back to the first user. Principle:
1. the first user browses a page.
2. the number of times the server program reads the page from the database or file.
3. store the number of times and send it back to the first user.
4. the second user browsed a page.
5. the number of times the server program reads the page from the database or file.
6. store the number of times and send it back to the second user.
Functions to be understood:
Fopen () open a file
Filesize () to get the file size
Fseek () move file pointer
Fgets () obtains the row content of the file pointer.
Fputs () writes the string as the position of the file pointer.
Fclose () close the file
File_exists () to determine whether a file exists
Exec () executes external programs
The simplest calculator:
Visitor counter prototype
/*
(C) 1998 David W. Bettis
Here is the copyright information
*/
$ CounterFile = "counter.txt ";
# Here is the definition counter file
Function displayCounter ($ counterFile ){
$ Fp = fopen ($ counterFile, "rw ");
# Open a file and use the read/write method
$ Num = fgets ($ fp, 5 );
# Obtain the current number
$ Num + = 1;
# Add 1
Print "you are the". "$ num". "bit boring ";
Exec ("rm-rf $ counterFile ");
Exec ("echo $ num> $ counterFile ");
# The Method of laziness. do not use fputs for writing.
}
If (! File_exists ($ counterFile )){
Exec ("echo 0> $ counterFile ");
} # If the recorder file does not exist, create it and set the content to 0.
DisplayCounter ($ counterFile );
?>
PHP stenographer is relatively simple:
# No copyright, so easy
$ Fp = fopen ("counter.txt", "r + ");
Flock ($ fp, 3 );
# Open the recorder file and lock it
$ Fsize = filesize ("count.txt ");
$ Count = fgets ($ fp, $ fsize + 1 );
$ Count ++;
# Obtain the digital and add one
Fseek ($ fp, 0 );
Fputs ($ fp, $ count );
Fclose ($ fp );
# Writing new digital data into a file
Echo "you are the $ count visitor ";
?>
PHP stenographer graphic version:
I will not elaborate on creating 10 images and concatenating numbers with pictures.
Fake Image: 0.gif ~ 9. gif
... $ Count is the obtained value.
$ Strcount = strval ($ count );
$ Strcount = chop ($ strcount );
$ Countlen = $ strlen ($ strcount );
$ Shtml = "";
For ($ I = 0; $ I <$ countlen; $ I ++ ){
$ Shtml. = "$ shtml. = $ strcount [$ I];
$ Shtml. = ". gif '> ";
}
Echo $ shtml;
?>
PHP stenographer database version:
Use the SQL calculator to create a table first
Create table counter
(
Counter int not null,
Id int not null
)
Insert into counter (counter, id) VALUE (0, 1)
$ Conn = mysql_connect (...,...,...);
# MySQL database connection
$ SQL = "select * from counter ";
$ Result = mysql_query ($ SQL, $ conn );
$ Objresult = mysql_fetch_object ($ result );
$ Count = $ objresult-> counter;
$ Count ++;
$ SQL = "update counter set counter =". $ count. "where id = 1 ";
Mysql_query ($ SQL, $ conn );
Mysql_close ($ conn );
Echo "you are the $ count guest ";
?>
Tip 1. the first user browses a page. 2. the number of times the server program reads the page from the database or file. 3. store the number of times and send it back to the first user ....