一個(gè)自定義位數(shù)的php多用戶計(jì)數(shù)器代碼
更新時(shí)間:2007年03月11日 00:00:00 作者:
此計(jì)數(shù)器能夠自定義任意位數(shù),而且在免費(fèi)提供的時(shí)候能夠顯示一個(gè)簡(jiǎn)單的廣告。
運(yùn)行的時(shí)候需要在計(jì)數(shù)器目錄下創(chuàng)建一個(gè)nobody帳戶有權(quán)改寫的目錄datas.
實(shí)際運(yùn)行的例子在
http://www.hnpts.ha.cn/freecount.htm
<?
Header("Content-type: image/png");
if ($user=="") $user="test";
$fn="datas/".$user.".txt";
if ($bit=="") $bit=8; //取默認(rèn)值
if (is_readable($fn)) {$f=fopen($fn,"r");
$c=fgets($f,255);fclose($f);} //讀出原來的計(jì)數(shù)值
else $c="0"; //新用戶
$l=strlen($c); //計(jì)算實(shí)際值長(zhǎng)度
$cnt="";
for ($i=0;$i<$bit-$l;$i++) $cnt.="0";//前面加“0”補(bǔ)足指定的位數(shù)
$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;}
//達(dá)到條件就顯示廣告
$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);
?>
運(yùn)行的時(shí)候需要在計(jì)數(shù)器目錄下創(chuàng)建一個(gè)nobody帳戶有權(quán)改寫的目錄datas.
實(shí)際運(yùn)行的例子在
http://www.hnpts.ha.cn/freecount.htm
<?
Header("Content-type: image/png");
if ($user=="") $user="test";
$fn="datas/".$user.".txt";
if ($bit=="") $bit=8; //取默認(rèn)值
if (is_readable($fn)) {$f=fopen($fn,"r");
$c=fgets($f,255);fclose($f);} //讀出原來的計(jì)數(shù)值
else $c="0"; //新用戶
$l=strlen($c); //計(jì)算實(shí)際值長(zhǎng)度
$cnt="";
for ($i=0;$i<$bit-$l;$i++) $cnt.="0";//前面加“0”補(bǔ)足指定的位數(shù)
$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;}
//達(dá)到條件就顯示廣告
$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);
?>
您可能感興趣的文章:
- PHP實(shí)現(xiàn)網(wǎng)站訪問量計(jì)數(shù)器
- PHP計(jì)數(shù)器的實(shí)現(xiàn)代碼
- php計(jì)數(shù)器的設(shè)計(jì)與實(shí)現(xiàn)
- php實(shí)現(xiàn)計(jì)數(shù)器方法小結(jié)
- 用PHP和MYSQL建立計(jì)數(shù)器過程詳解
- 壞狼php學(xué)習(xí) 計(jì)數(shù)器實(shí)例代碼
- 一個(gè)用php3編寫的簡(jiǎn)單計(jì)數(shù)器
- 調(diào)用WordPress函數(shù)統(tǒng)計(jì)文章訪問量及PHP原生計(jì)數(shù)器的實(shí)現(xiàn)
- php的計(jì)數(shù)器程序
- PHP簡(jiǎn)單實(shí)現(xiàn)文本計(jì)數(shù)器的方法
- PHP用函數(shù)嵌入網(wǎng)站訪問量計(jì)數(shù)器
相關(guān)文章
PHP后臺(tái)實(shí)現(xiàn)微信小程序登錄
這篇文章主要為大家詳細(xì)介紹了PHP后臺(tái)實(shí)現(xiàn)微信小程序登錄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08基于PHP+mysql實(shí)現(xiàn)新聞發(fā)布系統(tǒng)的開發(fā)
這篇文章主要介紹了基于PHP+mysql實(shí)現(xiàn)新聞發(fā)布系統(tǒng)的開發(fā),文章通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下 面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08thinkPHP框架RBAC實(shí)現(xiàn)原理分析
這篇文章主要介紹了thinkPHP框架RBAC實(shí)現(xiàn)原理,結(jié)合實(shí)例形式分析了thinkPHP框架中RBAC角色權(quán)限控制相關(guān)實(shí)現(xiàn)原理與操作技巧,需要的朋友可以參考下2019-02-02ThinkPHP查詢語句與關(guān)聯(lián)查詢用法實(shí)例
這篇文章主要介紹了ThinkPHP查詢語句與關(guān)聯(lián)查詢用法,以實(shí)例的形式常見的查詢方法,包括數(shù)組作為查詢條件及對(duì)象方式來查詢等技巧,需要的朋友可以參考下2014-11-11