簡單易用的計數器(資料庫)_PHP教程

WBOY
發布: 2016-07-21 16:06:18
原創
724 人瀏覽過

用法

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=0m_error_state. "";
function Counter($file,$query="",$add=1)
{
        $db_name="database $db_pass="password";
        $db_table="counter";

                $counter_error_state=-100;
                $counter_error_msg= "缺第一個參數或參數為空白";
                return -100;
      or_state,$counter_error_msg;
        if(empty($db_user)| |!$db_user||$db_user=="")$res=@mysql_connect("localhost");
        else $res=@mysql_connect("localhost !$res)
        {
                 or_msg="無法連接資料庫";
                return -10;
       db_name))
        {
                error_msg="無法選擇資料庫";
                return -11;
      {
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="不能建立資料表";
                                     }
                        @mysql_free_result($db_res);
                if(!$db_res=@mysql_query($str))         🎜 >                        return -30;
            $num=@mysql_num_rows($db_res);
                                     $counter_error_states=-40;
      ="發生沒有預期的錯誤=資料行數錯誤";
                                      $count=0;
              ";
                if($num==1)
                    $row=@mysql_fetch_array($db_res);
                                 $count=$row[" count"];
                        $id=$row["id"];                         ,$
                if($add                $str.=$db_table." SET file="".$file."",query="" .$query."",time="".date("Y;n;d;G; i;s")."",count=".$count.$strWhere;
            ($str);
                if(!$db_res)
                    $counter_error_states=-50;
                                   則返回-50;
                }
                🎜>? > 



http://www.bkjia.com/PHPjc/315451.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/315451.html

合適嗎?包括(計數器.php);Counter(__FILE__);// 為檔案增加一個統計if($PHP_SELF==/index.php) { $count=Counter(INDEX_COUNT);//為首頁增加一個統計} else { $ count=...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板