//counter_simple.php: 简单记数器
文本计数器
$count_num=0;
// 如果存放计数器文件已经存在,读取其中的内容
if(file_exists("counter.txt"))
{
/******************************
以只读方式打开counter.txt文件
counter.txt用来存放计数器的值
*******************************/
$fp = fopen("counter.txt", "r");
//读取计数器的前8位数字
$count_num = fgets($fp,9);
//浏览次数加一
$count_num++;
//关闭文件
fclose($fp);
}
/***************************
以只写的方式打开counter.txt文件
把最新的计数值放入该文件中
****************************/
$fp = fopen("counter.txt", "w");
//写入最新的值
fputs($fp, $count_num);
//关闭文件
fclose($fp);
for($i=1;$i{
echo "
 
\n";//显示空行}
//浏览器输出浏览次数
echo "
您好!第 $count_num 位顾客!
";?>
//counter_graph.php:图象记数器
/*********************************
定义本程序的输出是一幅图象
而且这副图象是gif格式的
浏览器使用本程序产生的图象
*********************************/
Header("Content-type: image/gif");
//变量$count_length是需显示的位数
$count_length=8;
//$str是需要显示的计数值
$str=0;
// 如果存放计数器文件已经存在,读取其中的内容
if ( file_exists("counter.txt") )
{
/******************************
以只读方式打开counter.txt文件
counter.txt用来存放计数器的值
*******************************/
$fp = fopen("counter.txt", "r");
$str = fgets($fp,$count_length+1);
fclose($fp);
}
$str++;
/***************************
以只写的方式打开counter.txt文件
把最新的计数值放入该文件中
****************************/
$fp = fopen("counter.txt", "w");
fputs($fp, $str);
fclose($fp);
$str_0 = $str;//$str_0存放计数值前面补0后的字符串
$len_old = strlen($str);//$len_old存放原有计数值的位数
/****************************
如果原有计数值的位数不足,
则在它的前面加0补齐
****************************/
for ($i=$len_old+1;$i{
$str_0 = "0".$str_0;
};
$font = 3;//定义字号
$im = imagecreate($count_length*11-1,16);
//新建图象
$black = ImageColorAllocate($im, 0,0,0);//黑色
$white = ImageColorAllocate($im, 255,255,255);//白色
//定义颜色
//把计数器的底色设置成黑色
imagefill($im, 0,0,$black);
/**********************
用白色显示计数器的值,
在每个数字之间都用线分隔
***********************/
ImageString($im,$font,1,0,$str_0[0],$white);
for ($i=1;$iimageline($im, $i*11-1,0,$i*11-1,16, $white);
ImageString($im,$font,$i*11+1,0,$str_0[$i],$white);
};
ImageGif($im);//输出gif图像文件
ImageDestroy($im);//释放该图像文件
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
