会员: 密码:  免费注册 | 忘记密码 | 会员登录 网页功能: 加入收藏 设为首页 网站搜索  
 安全技术技术文档
  · 安全配制
  · 工具介绍
  · 黑客教学
  · 防火墙
  · 漏洞分析
  · 破解专题
  · 黑客编程
  · 入侵检测
 安全技术论坛
  · 安全配制
  · 工具介绍
  · 防火墙
  · 黑客入侵
  · 漏洞检测
  · 破解方法
  · 杀毒专区
 安全技术工具下载
  · 扫描工具
  · 攻击程序
  · 后门木马
  · 拒绝服务
  · 口令破解
  · 代理程序
  · 防火墙
  · 加密解密
  · 入侵检测
  · 攻防演示
技术文档 > Web开发 > PHP
简单易用的计数器(数据库)
发表日期:2004-07-23 16:39:07作者: 出处:  

用法
<?
include("counter.php");
Counter(__FILE__);//为文件增加一个计数
if($PHP_SELF=="/index.php")
{
$count=Counter("INDEX_COUNT");//为首页增加一个计数
}
else
{
$count=Counter("INDEX_COUNT","",0);//取得首页计数
}
echo "你是第$count个访问者";
?>
--------counter.php-----------
<?
if(!isset($PHP_INCLUDE_COUNTER_PHP))
{$PHP_INCLUDE_COUNTER_PHP=__FILE;

$counter_error_state=0;
$counter_error_msg="";
function Counter($file,$query="",$add=1)
{
        $db_name="database";
        $db_user="username";
        $db_pass="password";
        $db_table="counter";

        if(empty($file))
        {
                $counter_error_state=-100;
                $counter_error_msg="缺少第一个参数或参数为空";
                return -100;
        }
        global $PHP_SELF,$QUERY_STRING,$counter_error_state,$counter_error_msg;
        if(empty($db_user)||!$db_user||$db_user=="")$res=@mysql_connect("localhost");
        else $res=@mysql_connect("localhost",$db_user,$db_pass);
        if(!$res)
        {
                $counter_error_states=-10;
                $counter_error_msg="不能连接数据库";
                return -10;
        }
        if(!@mysql_select_db($db_name))
        {
                $counter_error_states=-11;
                $counter_error_msg="不能选择数据库";
                return -11;
        }
        else
        {
                if(!$db_res=@mysql_query("SELECT * FROM ".$db_table))
                {
                        if(!$db_res=@mysql_query("CREATE TABLE ".$db_table." (id INTEGER AUTO_INCREMENT,PRIMARY KEY (id),file VARCHAR(255),query VARCHAR(255),time VARCHAR(255),count INT)"))
                        {
                                $counter_error_states=-20;
                                $counter_error_msg="不能创建数据表";
                                return -20;
                        }
                        @mysql_free_result($db_res);
                }
                $str="SELECT * FROM ".$db_table." WHERE file="".$file."" AND query="".$query.""";

                if(!$db_res=@mysql_query($str))
                {
                        $counter_error_states=-30;
                        $counter_error_msg="不能查询记录";
                        return -30;
                }
                $num=@mysql_num_rows($db_res);
                if($num>1)
                {
                        $counter_error_states=-40;
                        $counter_error_msg="发生没有预期的错误=数据行数错误";
                        return -40;
                }
                $count=0;
                $str="INSERT ";
                $strWhere="";
                if($num==1)
                {
                        $row=@mysql_fetch_array($db_res);
                        @mysql_free_result($db_res);
                        $count=$row["count"];
                        $id=$row["id"];
                        $str="UPDATE ";
                        $strWhere=" WHERE id=$id";
                }
                if($add<1)return $count;
                $count+=$add;
                $str.=$db_table." SET file="".$file."",query="".$query."",time="".date("Y;n;d;G;i;s")."",count=".$count.$strWhere;
                $db_res=@mysql_query($str);
                if(!$db_res)
                {
                        $counter_error_states=-50;
                        $counter_error_msg="不能添加或更新记录";
                        return -50;
                }
                return $count;
        }
}

}
?> 

返回顶部】 【打印本页】 【关闭窗口

关于我们 / 给我留言 / 版权举报 / 意见建议 / 网站编程QQ群   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net 加载时间 0.00156