PHP counter program: solves all possible titles

Source: Internet
Author: User
The general counter program uses the external program function exec (), but many host spaces (including charged) refuse to do this dangerous control. We have to use fread (), fwrite () and other file read and write functions, the key is to use which method fopen () to open the file. Tried

The general counter program uses the external program function exec (), but many host spaces (including charged) refuse to do this dangerous control.
We have to use fread (), fwrite () and other file read and write functions, the key is to use which method fopen () 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)
1 2/* This file is count \ conut. php */
3
4 $ countfile = 'Count/counter.txt ';
5
6if (! File_exists ('$ countfile ')){
7 $ fp = fopen ('$ countfile', 'w ');
8 $ num = 1;
9 fputs ($ fp, $ num, 8 );
10 fclose ($ fp );
11}
12 else {
13 $ fp = fopen ('$ countfile', 'rw ');
14 $ num = fread ($ fp, 8 );
15 $ num;
16 rewind ($ fp );
17 fputs ($ fp, $ num, 8 );
18 fclose ($ fp );
19}
20
21/* if you do not need to display numbers in the image, convert the following Until?> Change the previous part to echo ''. $ num.''; or something like */
22 $ len_str = strlen ($ num );
23for ($ I = 0; $ I <$ len_str; $ I ){
24 $ numbers_exploded = substr ($ num, $ I, 1 );
25 $ output_str = $ output_str .'';
26}
27 echo $ output_str;
28?>
Application method:
For example, create a new test. php file outside the count folder. For other statuses, modify the $ countfile path.
Directly require the count. php file (note the path) at the location where test. php is to be displayed ).


Echo 'You are the dede ';
Require ('Count/count. php ');
Echo 'visitor ';
?>

Kuafu sets the counter.txt file to be readable and writable. in Windows, the file permission is everyone, and in Linux it is at least 444. You need to apply FTP software to file permission settings on the Internet or in Linux.

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.