Heim  >  Artikel  >  Backend-Entwicklung  >  一个自定义位数的php多用户计数器代码_PHP教程

一个自定义位数的php多用户计数器代码_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:56:35775Durchsuche

此计数器能够自定义任意位数,而且在免费提供的时候能够显示一个简单的广告。
运行的时候需要在计数器目录下创建一个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$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);
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/318052.htmlTechArticle此计数器能够自定义任意位数,而且在免费提供的时候能够显示一个简单的广告。 运行的时候需要在计数器目录下创建一个nobody帐户有权改...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn