PHP counter Program: Solve all problems that may be encountered

Source: Internet
Author: User
Tags count fread php file require file permissions linux

The general counter program uses the Execute external program function exec (), but many host spaces (including charges) reject this dangerous operation.
We have to use Fread (), fwrite () and other files to read and write functions, the key is to use which way fopen () open the file. After having tried n times, it is proved that the following procedure is feasible and verified on the charge space.

Count Directory
|---count.php
|---counter.txt
|---0~9 digital gif picture (0.gif,..., 9.gif)
1<?
2/* This document 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);
Fclose ($FP);
11}
12else{
$FP =fopen ("$countfile", "rw+");
$num =fread ($FP, 8);
$num + +;
Rewind ($FP);
Fputs ($FP, $num, 8);
Fclose ($FP);
19}
20
21/* If you don't want the picture to display the number, change the following until?> to echo "<font color=red>". $num. " </font> ";
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}
27echo $output _str;
28?>
How to use:
For example, create a new test.php outside the Count folder. Other locations Please modify the $countfile path.
Directly require the count.php file (note path) where test.php is to be displayed.
<br>
<?php
echo "You are the first";
Require ("count/count.php");
echo "Guest";
?>
<br>

To emphasize the last question, please set the Counter.txt file to read and write, and under Windows file permissions under Everyone,linux at least 444. Files on the Web or Linux under the file permissions settings to use the FTP software.



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.