一个简单的免费php计数器
Jun 13, 2016 am 10:24 AM
count
create
php
table
u
。
free
suggestion
database
yes
use
of
Simple
manage
counter
this
这个是用数据库管理的。
建议数据库
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{$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();
?>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
