用法
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