作者pSeRiC (http://pseric.com )
看板Web_Design
标题Re: [问题] 纯文字的计数器要怎麽做呢
时间Mon Oct 2 00:54:25 2006
把以下存成 count.php
================================================
<?
$formatnumber = true; // add thousands separator? false disables it.
// ONLY EDIT BELOW IF YOU WANT AN HIT COUNTER RENDERED AS AN IMAGE
$showimage = false; // change to true to enable image render
$font = 2; // font style, 1-5. These are built in php fonts!
$fontcolour = "black"; // black or white font?
$bgcolor = "transparent"; // transparent or black background?
// DO NOT EDIT BELOW THIS LINE - DO THE CUSTOMISING IN THE PAGE YOU INCLUDE ON! //
$path = __FILE__;
$path = preg_replace( "'\\\count\.php'", "", $path);
$path = preg_replace( "'/count\.php'", "", $path);
$counter = $path."/hitcounter.dat";
if(file_exists($counter))
{
$fp = fopen($counter, "r+");
flock($fp, 1);
$count = fgets($fp, 4096);
$count += 1;
fseek($fp,0);
fputs($fp, $count);
flock($fp, 3);
fclose($fp);
}
else
{
print "<p>Error, could not find hitcounter.dat in ".$path.", please check it!</p>";
}
if($formatnumber)
{
$count_new = number_format($count, 2, ",", ",");
$count_new = substr($count_new, 0 , -3);
$count = $count_new;
}
if($showimage)
{
$width = imagefontwidth($font) * strlen($count);
$height = imagefontheight($font);
$im = @imagecreate($width, $height);
if(trim($bgcolor) == "black")
$background_color = imagecolorallocate($im, 0, 0, 0); // black background
else
{
$background_color = imagecolorallocate($im, 255, 255, 255); //white background
imagecolortransparent($im, $background_color);
}
if(trim($fontcolour) == "black")
$text_color = imagecolorallocate($im, 0, 0, 0); // black text
else
$text_color = imagecolorallocate($im, 255, 255, 255); // white text
imagestring($im, $font, 0, 0, $count, $text_color);
header("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
}
else
{
print $count;
}
?>
===============================
开一个 hitcounter.dat 档案 内容建入起始数字 并chmod 0777
===============================
要显示计数器的地方
<?php include("count.php"); ?>
--
免费硬碟免费相簿免费信箱免费网址免费留言板免费讨论区免费计数器免费翻译
免要找免费资源就来
费广播免费拨接免费转址免费部落格免费素材免费电子报免
费上传空间免费网址免费计数器免费翻译免费资源免费桌布免费线上扫毒免费讨
论区免费聊天 The Free Group 免费资源网路社群免费留言板免费拨接免费翻译
免费电子报免费贺卡免费扫毒免费广播免费拨接http://www.FreeGroup.org免费
免费贺卡免费扫毒免费广播免费拨接免费转址免费部落格免费素材免费电子报免
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.171.118.131