【 tulaoshi.com - PHP 】
用法
<?
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)"))
{
&