這個是用資料庫管理的。
建議資料庫
create table count(
userid varchar(20) not null,
count varchar(20) not null,
ip varchar(20) not null
);
申請頁面
計數器申請
if(!isset($submit))
{
?>
}
else
{
$mysql_db=mysql_connect("localhost","root","") or die("資料庫連接失敗");
mysql_select_db("footboy",$mysql_db) or die("資料庫選表失敗");
$sql="select * from count where userid=$userid";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
$ip=getenv("remote_addr");
if($num || $userid=="")//判斷該ID是否存在,及輸入是否正確
{
printf("%s已經存在或輸入為空白",$userid);
print("返回");
mysql_close();
}
else
{
$insert="INSERT INTO count VALUES($userid,1,$ip)";//滿足條件,記錄資料
mysql_query($insert);
print("$userid,恭喜您申請成功返回
");
print("您可以用以下代碼應用http://footboy.host.wayall.com/count/count.php?userid=$userid");
mysql_close();
}
}
?>
應用頁面
$mysql_db=mysql_connect("localhost","root","");//串連資料庫
mysql_select_db("footboy",$mysql_db);
$sql="select * from count where userid=$userid";//資料庫查詢
$result=mysql_query($sql);
$sql_row=mysql_fetch_array($result);
$num=mysql_num_rows($result);//判斷使用者是否已經申請
$count=$sql_row[count];//取出計數器資料
//將資料格式化成5位
$count_len=strlen($count);
for($i=0;$i<5-$count_len;$i++)
{$count="0".$count;}
//取得瀏覽使用者IP,防止重複重新整理
$ip=getenv("remote_addr");
if($num)
{
if($ip!=$sql_row[ip])
{
$sql_row[count]++;//條件滿足開始記數輸出
printf("您是第%s個瀏覽本站的
",$count);
mysql_query("update count set count=$sql_row[count],ip=$ip where userid=$userid");//存入資料
mysql_close();
}
else
{
printf("您是第%s個瀏覽本站的
",$count);
print("歡迎您再次光臨本站");
}
}
else
printf("%s使用者不存在,請先申請",$userid);
mysql_close();
?>
http://www.bkjia.com/PHPjc/532167.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532167.htmlTechArticle這個是用資料庫管理的。 建議資料庫 create table count( userid varchar(20) not null, count varchar(20) not null, ip varchar(20) not null ); 申請頁面 計數器申請...