程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 一個自定義位數的php多用戶計數器代碼

一個自定義位數的php多用戶計數器代碼

編輯:關於PHP編程

此計數器能夠自定義任意位數,而且在免費提供的時候能夠顯示一個簡單的廣告。
運行的時候需要在計數器目錄下創建一個nobody帳戶有權改寫的目錄datas.
實際運行的例子在
http://www.hnpts.ha.cn/freecount.htm
<?
Header("Content-type: image/png");
if ($user=="") $user="test";
$fn="datas/".$user.".txt";
if ($bit=="") $bit=8;   //取默認值
if (is_readable($fn)) {$f=fopen($fn,"r");
$c=fgets($f,255);fclose($f);} //讀出原來的計數值
else $c="0"; //新用戶
$l=strlen($c);  //計算實際值長度
$cnt="";
for ($i=0;$i<$bit-$l;$i++) $cnt.="0";//前面加“0”補足指定的位數
$cnt.=$c;$c1=intval($c);$c1++;
$f=fopen($fn,"w");fputs($f,$c1);fclose($f); //寫回
  $font=20;
if (($c1%10==9)&&($user!="test")) {$cnt="www.hnpts.ha.cn";$font=16;}
//達到條件就顯示廣告
$s=ImageTTFBBox($font,0,"times.ttf", $cnt);
$x=abs($s[4])+8;$y=abs($s[5])+7;
$im = imagecreate($x,$y);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
if ($font==20) {$green = ImageColorAllocate($im, 0,255,0);
imagerectangle($im,1,1,$x-2,$y-2,$white);}
else $green = ImageColorAllocate($im, 255,255,255);
ImageTTFText($im,$font,0, 3,$y-5, $green, "times.ttf", $cnt);
ImagePng($im);
ImageDestroy($im);
?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved