电脑安全

您当前的位置:主页 > 电脑安全 >

php实现计数器功能-网络编程

来源:[db:来源]标题:   新宋体    编辑:电脑技术全能网 时间:2019-09-20 06:24

原标题:php实现计数器功能-网络编程
   <?php/****计数器(v1.1.0)**Version:1.1.0*Author:村长*PHP:>4.3**/classCounter{var$CountFolder;var$countType;var$showtype;var$imgArray;functionCounter(){$this->countType=0;$this->showtype="GetCountByDay";$this->imgArray=array();$this->MakeCounter();}functionMakeCounter(){$this->CountFolder="log/".date("Ymd");if(!is_dir($this->CountFolder)){mkdir($this->CountFolder,0777);}$this->_DoCount();}//Savedatafilefunction_DoCount(){$file=date("Ymd").ip2long($_SERVER['REMOTE_ADDR']).".txt";if(!file_exists($this->CountFolder."/".$file)){$fp=@fopen($this->CountFolder."/".$file,"wb+");//这里能够保留其余须要的日记记载@fputs($fp,$_SERVER['REMOTE_ADDR']);@fclose($fp);}}//取得指准时间的统计数据//默许为1天0为取全部functionGetCountByDay($day=1){//本日的时光戳$today=strtotime(date("Y-m-d"));$all=0;for($i=$day;$i>=0;$i--){$tsp=$today-(86400*$i);$folder="log/".date("Ymd",$tsp)."/*.txt";$ta=glob("$folder");$all=$all+count($ta);}return$all;}functionGetCountUseImg($day=1){$allnumber=$this->GetCountByDay($day);for($i=0;$i<strlen($allnumber);$i++){$idx=substr($allnumber,$i,1);$returnVal.=sprintf("<imgsrc=/"%s/">",$this->imgArray[$idx]);}return$returnVal;}functionSetStyle($style='',$ext="gif"){$imgprefix="img/";$folder=$imgprefix.$style;foreach(range(0,9)as$num){$this->imgArray[$num]=$folder."/".$num.".$ext";}if(is_dir($folder)){$this->showtype="GetCountUseImg";}else{$this->showtype="GetCountByDay";}}functionShow($day=0){return$this->{$this->showtype}($day);}}//实例计数器工具$counter=newCounter();//采纳sports98款式表现,告诉默许扩大名为png格局$counter->SetStyle("sports98","png");echo"<br/>本日拜访:".$counter->Show(0);//采纳S1款式表现,默许扩大名为gif$counter->SetStyle("s1");echo"<br/>近3日拜访:".$counter->Show(2);//----只表现笔墨的计数器$counter->SetStyle("-");echo"<br/>近3日拜访:".$counter->Show(2);?>

上一篇:php 图片验证码-网络编程

下一篇:没有了