Three php counter code _ PHP tutorials

Source: Internet
Author: User
Three php counter codes. Three php counter codes are added to the article. All three of them share the same common point, that is, they do not need a database, but use text files to view and Count Web pages on instances. Three articles are added to the favorites. three php counter codes are added to the favorites. All three of them share the same vertices, that is, they do not need databases. Instead, they use text files to view and Count Web pages on instances.

Three php Tutorial counter codes are added to the article. The three of them share the same common point, that is, they do not need database tutorials, but use text files to view and Count Web pages on instances.

// Counter
Function countx ($ file = "count. dat "){
If (file_exists ($ file )){
$ Fp = fopen ($ file, "r ");
$ Numx = fgets ($ fp, 10 );
Fclose ($ fp );
$ Numx ++;
// The above four lines of code can be replaced by an expression: $ numx = file_get_contents ($ file) + 1;
}
Else {
$ Numx = 1 ;}
File_put_contents ($ file, $ numx); // when the file does not exist, this function automatically creates the file and converts the parameter to a string for writing.
Echo $ numx;
/* The entire function body can be replaced by two expressions: file_exists ($ file )? File_put_contents ($ file, file_get_contents ($ file) + 1): file_put_contents ($ file, "1"); readfile ($ file );
*/
}
// Function call
Countx ();
?>

Code 2



$ Counterfile = "balong.txt"; // number of file names for storing numeric values

Function displaycounter ($ counterfile ){
$ Fp = fopen ($ counterfile, "rw ");
$ Num = fgets ($ fp, 5 );
$ Num + = 1;
Print "you are the". "$ num". "guy reading the barrier counter ";
Exec ("rm-rf $ counterfile ");
Exec ("echo $ num> $ counterfile ");
}

If (! File_exists ($ counterfile )){
Exec ("echo 0> $ counterfile ");
}

Displaycounter ($ counterfile );

?>


Code 3



$ Counterfile = "www.bkjia.com.txt"; // number of file names for storing numeric values

Function displaycounter ($ counterfile ){
$ Fp = fopen ($ counterfile, "rw ");
$ Num = fgets ($ fp, 5 );
$ Num + = 1;
Print "you are the". "$ num". "guy reading the barrier counter ";
Exec ("rm-rf $ counterfile ");
Exec ("echo $ num> $ counterfile ");
}

If (! File_exists ($ counterfile )){
Exec ("echo 0> $ counterfile ");
}

Displaycounter ($ counterfile );

?>


Bytes. Three articles are added to your favorites...

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.