PHP制作图型计数器的例子

来源:互联网 发布:荣誉证书制作软件 编辑:程序博客网 时间:2024/05/16 07:48
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
以前在奥索看见过很多这样的例子,各各方法复杂,请看如下例子实现图形计数器。在网页中使用请用 <script src="http://文件地址"></script>

<?
//存放计数的文本文件
$count="count.txt";
//计数器的位数,如果不填则默认为6位
$wei="";
//图像的URL路径
$tu="http://127.0.0.1/tcount/images";
?>
<?
if ($wei=="") { $wei=6; }
if (!file_exists($count)) { $fp=fopen($count,"w+"); fputs($fp,0,100); fclose($fp); }
if ($REMOTE_ADDR!=$ip)     {
$fp=fopen($count,"r+");
$cc=fgets($fp,100);
$cc=trim($cc);
if ($cc=="") { $cou=1; }
else { $cou=$cc+1; }
rewind($fp);
fputs($fp,$cou,100);
fclose($fp);
                             }
setcookie("ip",$REMOTE_ADDR,time()+86400);
$fp=fopen($count,"r+");
$cou=fgets($fp,100);
$cou=trim($cou);
fclose($fp);
$w=strlen($cou);
while($w<$wei) {
$cou="0".$cou;
$w++;
                }
$www=strlen($cou);
$i=0;
echo "document.write(/"<p align=center>/");/n";
while($i<$www) {
$ym=substr($cou,$i,1);
echo "document.write(/"<img src=$tu/$ym.gif>/");/n";
$i++;
  }
?> <script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>