Home > Backend Development > PHP Tutorial > Web page counter code written in php_PHP tutorial

Web page counter code written in php_PHP tutorial

WBOY
Release: 2016-07-13 10:58:01
Original
1249 people have browsed it



Web page counter code written in php tutorial

$countfile = "counter.txt";
//The file that defines the counter is written to the counter.txt file in the current directory, and then we should test whether the file can be opened
if (($fp = fopen($countfile, "r+")) == false) {
//Open the file in read-write mode, exit if it cannot be opened
printf ("open file %s failed!",$countfile);
exit;
}
else
{
//If the file can be opened normally, read the data in the file, assuming it is 1
$count = fread ($fp,10);
//Read 10-bit data
$count = $count + 1;
//count++
fclose ($fp);
//Close the current file
$fp = fopen($countfile, "w+");
//Open the file in overwrite mode
fwrite ($fp,$count);
//Write new data after adding 1
fputs($fp,$fg);
//Display counting results
//Number display
echo "

Count times: $count
";

//Graphic mode count
$fp = fopen ($countfile, "r"); //Open the file in read-only mode
$array_count = 1; //Define a variable that represents the position of the array element, use
below while (! feof($fp)) {
$current_number = fgetc($fp);
$counter_array[$array_count] = $current_number;
$array_elements = count ($counter_array);
$array_count = $array_count + 1;
}
echo "

Number of counts:";
for ($array_id = 1;$array_id < $array_elements; ++ $array_id) {
echo "";
}
echo "
";

fclose ($fp);
//And close the file
}

?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632038.htmlTechArticlehtml head titlephp tutorial to write web page counter code/title head body ?php $countfile = counter.txt; // The file that defines the counter is written to the counter.txt file in the current directory, and then I...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template