PHP counter program: solves all possible problems _ PHP Tutorial

Source: Internet
Author: User
PHP counter program: solves all possible problems. The general counter program executes the external program function exec (), but many host spaces (including charged) refuse this dangerous operation. We have to use fread (), fwrite () and other file read/write functions. Generally, the counter program executes the external program function exec (), but there are a lot of host space (including charged) reject this dangerous operation.
We have to use fread (), fwrite (), and other file read/write functions. The key lies in which method fopen () is used to open the file. After N attempts, it is confirmed that the following procedures are feasible and have been verified in the billable space.

Count Directory
| --- Count. php
| ---Counter.txt
| --- 0 ~ 9th digital gif image (0.gif, ...9.gif)
/* This file is countconut. php */

$ Countfile = "count/counter.txt ";

If (! File_exists ("$ countfile ")){
$ Fp = fopen ("$ countfile", "w ");
$ Num = 1;
Fputs ($ fp, $ num, 8 );
Fclose ($ fp );
}
Else {
$ Fp = fopen ("$ countfile", "rw ");
$ Num = fread ($ fp, 8 );
$ Num;
Rewind ($ fp );
Fputs ($ fp, $ num, 8 );
Fclose ($ fp );
}

/* If you do not need to display numbers in the image, convert the following Until?> Change the previous part to echo "". $ num. ""; and so on */
$ Len_str = strlen ($ num );
For ($ I = 0; $ I <$ len_str; $ I ){
$ Numbers_exploded = substr ($ num, $ I, 1 );
$ Output_str = $ output_str ."";
}
Echo $ output_str;
?>
Usage:
For example, create a new test. php file outside the count folder. For other locations, modify the $ countfile path.
Directly require the count. php file (focusing on the path) where test. php is to be displayed ).


Echo "you are the first ";
Require ("count/count. php ");
Echo "guest ";
?>



Tune the last question. set the counter.txt file to read and write. in Windows, the file permission is everyone, and in Linux it is at least 444. For files on the Internet or files in Linux, you must use the FTP software.

Deny exec (), but many host spaces (including charged) reject this dangerous operation. We have to use fread (), fwrite () and other file read and write functions...

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.