一个简单的免费php计数器
时间:2007-02-17 来源:PHP爱好者
这个是用数据库管理的。
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
建议数据库
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
create table count(
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
userid varchar(20) not null,
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
count varchar(20) not null,
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
ip varchar(20) not null
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
申请页面
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<html>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<head>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<title>计数器申请</title>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</head>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<body>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<?
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
if(!isset($submit))
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
?>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<form name="form" method="post" action="index.php">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
用户名:
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<input type="text" name="userid">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<input type="submit" name="submit" value="申请">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</form>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<form name="form2" method="post" action="count.php">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
用户名:
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<input type="text" name="userid">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<input type="submit" name="submit2" value="应用">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</form>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<?
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
else
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$mysql_db=mysql_connect("localhost","root","") or die("数据库连接失败");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_select_db("footboy",$mysql_db) or die("数据库选表失败");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$sql="select * from count where userid='$userid'";
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$result=mysql_query($sql);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$num=mysql_num_rows($result);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$ip=getenv("remote_addr");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
if($num || $userid=="")//判断该ID是否存在,及输入是否正确
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
printf("%s已经存在或输入为空",$userid);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
print("<a href='index.php'>返回</a>");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_close();
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
else
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$insert="INSERT INTO count VALUES('$userid','1','$ip')";//满足条件,记录数据
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_query($insert);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
print("$userid,恭喜您申请成功<a href='index.php'>返回</a><br>");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
print("您可以用以下代码应用http://footboy.host.wayall.com/count/count.php?userid=$userid");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_close();
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
?>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</body>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</html>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
应用页面
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<?
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$mysql_db=mysql_connect("localhost","root","");//连接数据库
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_select_db("footboy",$mysql_db);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$sql="select * from count where userid='$userid'";//数据库查询
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$result=mysql_query($sql);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$sql_row=mysql_fetch_array($result);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$num=mysql_num_rows($result);//判断用户是否已经申请
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$count=$sql_row[count];//取出计数器数据
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
//将数据格式化成5位
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$count_len=strlen($count);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
for($i=0;$i<5-$count_len;$i++)
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{$count="0".$count;}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
//取得浏览用户IP,防止重复刷新
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$ip=getenv("remote_addr");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
if($num)
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
if($ip!=$sql_row[ip])
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$sql_row[count]++;//条件满足开始记数输出
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
printf("您是第%s个浏览本站的<br>",$count);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_query("update count set count='$sql_row[count]',ip='$ip' where userid='$userid'");//存入数据
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_close();
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
else
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
printf("您是第%s个浏览本站的<br>",$count);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
print("欢迎您再次光临本站");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
else
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
printf("%s用户不存在,请先<a href='index.php'>申请</a>",$userid);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_close();
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
?>
php爱好者站 http://www.phpfans.net php基础|php进阶|php模板.
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
建议数据库
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
create table count(
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
userid varchar(20) not null,
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
count varchar(20) not null,
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
ip varchar(20) not null
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
申请页面
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<html>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<head>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<title>计数器申请</title>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</head>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<body>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<?
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
if(!isset($submit))
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
?>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<form name="form" method="post" action="index.php">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
用户名:
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<input type="text" name="userid">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<input type="submit" name="submit" value="申请">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</form>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<form name="form2" method="post" action="count.php">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
用户名:
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<input type="text" name="userid">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<input type="submit" name="submit2" value="应用">
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</form>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<?
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
else
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$mysql_db=mysql_connect("localhost","root","") or die("数据库连接失败");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_select_db("footboy",$mysql_db) or die("数据库选表失败");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$sql="select * from count where userid='$userid'";
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$result=mysql_query($sql);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$num=mysql_num_rows($result);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$ip=getenv("remote_addr");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
if($num || $userid=="")//判断该ID是否存在,及输入是否正确
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
printf("%s已经存在或输入为空",$userid);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
print("<a href='index.php'>返回</a>");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_close();
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
else
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$insert="INSERT INTO count VALUES('$userid','1','$ip')";//满足条件,记录数据
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_query($insert);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
print("$userid,恭喜您申请成功<a href='index.php'>返回</a><br>");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
print("您可以用以下代码应用http://footboy.host.wayall.com/count/count.php?userid=$userid");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_close();
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
?>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</body>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
</html>
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
应用页面
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
<?
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$mysql_db=mysql_connect("localhost","root","");//连接数据库
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_select_db("footboy",$mysql_db);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$sql="select * from count where userid='$userid'";//数据库查询
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$result=mysql_query($sql);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$sql_row=mysql_fetch_array($result);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$num=mysql_num_rows($result);//判断用户是否已经申请
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$count=$sql_row[count];//取出计数器数据
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
//将数据格式化成5位
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$count_len=strlen($count);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
for($i=0;$i<5-$count_len;$i++)
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{$count="0".$count;}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
//取得浏览用户IP,防止重复刷新
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$ip=getenv("remote_addr");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
if($num)
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
if($ip!=$sql_row[ip])
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
$sql_row[count]++;//条件满足开始记数输出
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
printf("您是第%s个浏览本站的<br>",$count);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_query("update count set count='$sql_row[count]',ip='$ip' where userid='$userid'");//存入数据
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_close();
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
else
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
{
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
printf("您是第%s个浏览本站的<br>",$count);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
print("欢迎您再次光临本站");
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
}
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
else
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
printf("%s用户不存在,请先<a href='index.php'>申请</a>",$userid);
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
mysql_close();
China It Power . ComkJ1LxdaM8d5ZTwTrhRrJiLO2c
?>
php爱好者站 http://www.phpfans.net php基础|php进阶|php模板.
相关阅读 更多 +