<?php 
/*
乘风多用户PHP统计系统
作者QQ：178575
作者E-Mail：yliangcf@163.com
作者网站：http://www.qqcf.com
详细介绍：http://www.qqcf.com/cfstat.htm
上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
因为这些内容可能时常更新，就没有放在程序里，请自己上网站上查看
有完整版本的演示
*/
?>
<?php 
//以下为公用函数
function goback($str,$alertstr)//为空时后退
{ 
 if($str=="")
 {
  echo "<script>";
  echo "alert('".$alertstr."');";
  echo "history.go(-1)";
  echo "</script>";
  exit;
 }
 else
 {
  return $str;
 }
}

function alertback($alertstr,$backnum)
{
  echo "<script>";
  echo "alert('".$alertstr."');";
  echo "history.go(-".$backnum.")";
  echo "</script>";
  exit;
}

function alerturl($alertstr,$url)
{
  echo "<script>";
  echo "alert('".$alertstr."');";
  echo "location.href='".$url."';";
  echo "</script>";
  exit;
}

function alertclose($alertstr)
{
  echo "<script>";
  echo "alert('".$alertstr."');";
  echo "window.close();";
  echo "</script>";
  exit;
}

function gotourl($url)
{
  echo "<script>";
  echo "location.href='".$url."';";
  echo "</script>";
  exit;
}

function chkstr($paravalue,$paratype) //过滤非法字符
{
 if($paratype==1)
 {
  $filterstr="(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
  if (preg_match("/".$filterstr."/is",$paravalue)==1){   
   echo "传递的参数类型有错误！";
   exit;
  }

  $inputstr=str_replace("'","''",$paravalue);
  }
 elseif($paratype==2)
 {
   if($paravalue!=""&&is_numeric($paravalue)==false)
   {
     echo "传递的参数类型有错误！";
     exit;
	}
   else
   { 
    $inputstr=$paravalue;
    }
 }
 elseif($paratype==3)
 {
   if($paravalue!=""&&(strtotime($paravalue)==false||strtotime($paravalue)==-1))
   {
     echo("传递的参数类型有错误！");
     exit;
   }
   else
   { 
    $inputstr=$paravalue;
    }
 }

 return $inputstr;
}


function httppath($assort)
{
 $ser=$_SERVER['HTTP_HOST'];
 $scr=$_SERVER['SCRIPT_NAME'];

 $scr_2=substr($scr,0,strrpos($scr,"/")+1);

 if($assort==1)
 {
  $httppath=$ser;
 }
 elseif($assort==2)
 {
   $httppath="http://".$ser.$scr_2;
 }
 elseif($assort==3)
 {
   $httppath="http://".$ser.$scr;
 }

return $httppath;
}


function breakurl($url)
{
 if($url<>"")
 {
  $urlarrary=explode("/",$url);
  $breakurl=$urlarrary[2];
 }
 else
 {
  $breakurl=$url;
 }
 return $breakurl;
}

function pxfilter($px,$pxok)
{
$px=strtolower($px);
$pxok=strtolower($pxok);

$myarray=explode(",",$pxok);

for ($i=0;$i<=count($myarray)-1;$i++){
 if($myarray[$i]==$px)
 {
  $j=1;
 }
}

 if($j<>1) alertback("禁止此类排序",1);
}

function getsearchkeyword($url,$keywordflag){

 if(strpos($url, "?".$keywordflag."=")!==false)
 {
  $keywordflag="?".$keywordflag."=";
 }

 if(strpos($url, "&".$keywordflag."=")!==false)
 {
  $keywordflag="&".$keywordflag."=";
 }

 $urlarrary=explode($keywordflag,$url);

 $urltail=$urlarrary[1];

  
 if(strpos($urltail,"&")==false){
     $searchkeyword=substr($urltail,0,1000);	
 }
 else{
	 $searchkeyword=substr($urltail,0,strpos($urltail,"&"));	 
  }

 return $searchkeyword;
}

function getiparea($ip) {
 $array=explode('.',$ip);
 $ipint=($array[0] * 256*256*256) + ($array[1]*256*256) + ($array[2]*256) + $array[3];
 $sql="select * from cfstat_ipaddress where $ipint>=ip_1 and $ipint<=ip_2";
 $result=mysql_query($sql);
 $rs=mysql_fetch_assoc($result);
 if($rs)
 {
   $iparea=$rs["area"]."-".$rs["area_2"]."-".$rs["area_3"];
 }
 else
 {
  $iparea="<a href='&#104;&#116;&#116;&#112;&#58;&#47;&#47;&#119;&#119;&#119;&#46;&#113;&#113;&#99;&#102;&#46;&#99;&#111;&#109;' target=_blank>&#73;&#80;&#25968;&#25454;&#24211;&#26080;&#25968;&#25454;&#45;&#19979;&#36733;</a>";
 }
 
 return $iparea;
}

function getskincolor($skincolor,$assort){
 $myarray=explode("|",$skincolor);

 
 if($assort<=count($myarray)){
  return $myarray[$assort];
 }
}


function watermark(
	$infilename,
	$string,
	$fontfilename,
	$fontsize,
	$distancefromborder,
	$fontcolorarray,
	$shadecolorarray,
	$stringbottom)
{

  $imagefile=fopen($infilename,"r");
  $imagestring=fread($imagefile,filesize($infilename));
  fclose($imagefile);
  $image=ImageCreateFromString($imagestring);
  $imagewidth=ImageSX($image);
  $imageheight=ImageSY($image);
  $stringbox=ImageTTFBBox($fontsize,0,$fontfilename,$string);
  $stringwidth=$stringbox[2]-$stringbox[0];
  $stringheight=$stringbox[1]-$stringbox[7];
  $stringright=$imagewidth-$distancefromborder;
  $stringleft=10;
  //$stringbottom=20;
  $stringtop=0;
  $fontcolor=ImageColorAllocateAlpha($image,
    $fontcolorarray[0],
    $fontcolorarray[1],
    $fontcolorarray[2],
    $fontcolorarray[3]);
  $shadecolor=ImageColorAllocateAlpha($image,
    $shadecolorarray[0],
    $shadecolorarray[1],
    $shadecolorarray[2],
    $shadecolorarray[3]);
ImageTTFText($image,$fontsize,0,$stringleft,$stringbottom-1,$shadecolor,$fontfilename,$string);
ImageTTFText($image,$fontsize,0,$stringleft+1,$stringbottom,$shadecolor,$fontfilename,$string);
ImageTTFText($image,$fontsize,0,$stringleft,$stringbottom+1,$shadecolor,$fontfilename,$string);
ImageTTFText($image,$fontsize,0,$stringleft-1,$stringbottom,$shadecolor,$fontfilename,$string);

ImageTTFText($image,$fontsize,0,$stringleft,$stringbottom,$fontcolor,$fontfilename,$string);
  $outfilename=substr($infilename,0,-4)."_$string.png";
  header("Content-type: image/png");
  ImagePng($image);
  ImageDestroy($image);
}


function getostype(){

$agentinfo = $_SERVER['HTTP_USER_AGENT'];

if(strpos($agentinfo,'NT 6.1')!=false){
 $ostype = "Windows 7";
}
elseif(strpos($agentinfo,'NT 6.0')!=false){
 $ostype = "Windows Vista";
}
elseif(strpos($agentinfo,'NT 5.2')!=false){
 $ostype = "Windows 2003";
}
elseif(strpos($agentinfo,'NT 5.1')!=false){
 $ostype = "Windows XP";
}
elseif(strpos($agentinfo,'NT 5')!=false){
 $ostype = "Windows 2000";
}
elseif(strpos($agentinfo,'NT 4.9')!=false){
 $ostype = "Windows ME";
}
elseif(strpos($agentinfo,'NT 4')!=false){
 $ostype = "Windows NT4";
}
elseif(strpos($agentinfo,'NT 98')!=false){
 $ostype = "Windows 98";
}
elseif(strpos($agentinfo,'NT 95')!=false){
 $ostype = "Windows 95";
}
elseif(strpos($agentinfo,'NT')!=false){
 $ostype = "Windows";
}
elseif(strpos($agentinfo,'Mac')!=false){
 $ostype = "Mac";
}
elseif(strpos(strtolower($agentinfo),'unix')!=false){
 $ostype = "Unix";
}
elseif(strpos(strtolower($agentinfo),'linux')!=false){
 $ostype = "Linux";
}
elseif(strpos(strtolower($agentinfo),'sunos')!=false){
 $ostype = "SunOS";
}
else{
 $ostype = "其他";
}

return $ostype;
}


function getbrowsertype(){

$agentinfo = $_SERVER['HTTP_USER_AGENT'];

if(strpos(strtolower($agentinfo),'maxthon')!=false){
 $browsertype = "Maxthon";
}
elseif(strpos($agentinfo,'TencentTraveler')!=false){
 $browsertype = "TencentTraveler";
}
elseif(strpos($agentinfo,'Firefox')!=false){
 $browsertype = "Firefox";
}
elseif(strpos($agentinfo,'360SE')!=false){
 $browsertype = "360SE";
}
elseif(strpos($agentinfo,'Opera')!=false){
 $browsertype = "Opera";
}
elseif(strpos($agentinfo,'Chrome')!=false){
 $browsertype = "Chrome";
}
elseif(strpos($agentinfo,'Safar')!=false){
 $browsertype = "Safar";
}
elseif(strpos($agentinfo,'TheWorld')!=false){
 $browsertype = "TheWorld";
}
elseif(strpos($agentinfo,'GreenBrowser')!=false){
 $browsertype = "GreenBrowser";
}
elseif(strpos($agentinfo,'MSIE 6.0')!=false){
 $browsertype = "IE 6.0";
}
elseif(strpos($agentinfo,'MSIE 7.0')!=false){
 $browsertype = "IE 7.0";
}
elseif(strpos($agentinfo,'MSIE 8.0')!=false){
 $browsertype = "IE 8.0";
}
elseif(strpos($agentinfo,'IE')!=false){
 $browsertype = "IE";
}
else{
 $browsertype = "其他";
}

return $browsertype;
}

function getmicrotime()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}


?>