今天给大家分享的是由图老师小编精心为您推荐的php计数器的设计与实现,喜欢的朋友可以分享一下,也算是给小编一份支持,大家都不容易啊!
【 tulaoshi.com - Web开发 】
本程序有4个计数器。?
//------[ 基本设定 ]-------
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "512783";
$mysql_database = "jishuqi";
//-------
//准备好你的sql
$sql = "INSERT INTO `counter_1` ( `user` , `ip` , `time` ) VALUES ('$user', '$ip', NOW( ) );";
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
//$id = mysql_insert_id();
mysql_close($conn);
//建立连接------通过(伺服器地址,使用者名称,使用者密码)
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
//准备好你的SQL语法
$sql = "SELECT COUNT(*) FROM `counter_1`";
//进行查询(或者叫做执行,选取)
$result=mysql_db_query( $mysql_database, $sql,$conn );
//将查询后的结果--抓出一笔
$row1=mysql_fetch_row($result);
//印出该笔资料的所有栏位的阵列
//print_r($row1);
//清除查询结果
mysql_free_result($result);
//建立连接------通过(伺服器地址,使用者名称,使用者密码)
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
//准备好你的SQL语法
$sql = "SELECT COUNT(*) FROM `counter_1` WHERE user='$user'";
//进行查询(或者叫做执行,选取)
$result=mysql_db_query( $mysql_database, $sql,$conn );
//将查询后的结果--抓出一笔
$row2=mysql_fetch_row($result);
//印出该笔资料的所有栏位的阵列
//print_r($row2);
//清除查询结果
mysql_free_result($result);
?
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
html
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
title3种计数器/title
style type="text/css"
!--
.style1 {
font-size: 24px;
color: #00FF99;
}
.style2 {color: #FF00FF}
.style3 {color: #CC0033}
.style4 {color: #0000FF}
.style5 {color: #FF0000}
.style6 {
font-size: 36px;
color: #996633;
}
--
/style
/head
body
div align="center" class="style1 style6"枫树林下
/div
div align="center"
p class="style1" /p
p class="style1" /p
p class="style1"span class="style3"总共有/span?=$row1[0]; ?span class="style5"人/spanspan class="style4"来过/spanspan class="style2"这个网站
/span/p
p class="style1"span class="style3"总共有/span?=$row2[0]; ?span class="style5"人/spanspan class="style4"来过/spanspan class="style2"?=$user?网站
/span
/p
/div
/body
/html
?
//------[基本设定]-------
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "512783";
$mysql_database = "jishuqi";
//-------
//建立连接------通过(伺服器地址,使用者名称,使用者密码)
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
//准备好你的SQL语法
$sql = "SELECT COUNT(*) FROM `counter_1`WHERE user= '$user' AND TIME_TO_SEC(NOW()-`time`) 3 AND ip='$REMOTE_ADDR'";
//进行查询(或者叫做执行,选取)
$result=mysql_db_query( $mysql_database, $sql,$conn );
//将查询后的结果--抓出一笔
$row=mysql_fetch_row($result);
//印出该笔资料的所有栏位[阵列]
//print_r($row);
//清除查询结果
mysql_free_result($result);
if($row[0]==0)
{
//--基本设定
//准备好你的sql
$sql = "INSERT INTO `counter_1` ( `user` , `ip` , `time` ) VALUES ('$user', '$REMOTE_ADDR', NOW( ) );";
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
$id = mysql_insert_id();
mysql_close($conn);
}
//建立连接------通过(伺服器地址,使用者名称,使用者密码)
$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password );
//准备好你的SQL语法
$sql = "SELECT COUNT(*) FROM `counter_1` WHERE user='$user'";
//进行查询(或者叫做执行,选取)
$result=mysql_db_query( $mysql_database, $sql,$conn );
//将查询后的结果--抓出一笔
$row=mysql_fetch_row($result);
//印出该笔资料的所有栏位的阵列
//print_r($row);
//清除查询结果
mysql_free_result($result);
for ( $i=0; $i strlen($row[0]);$i++)
{
$digit= substr($row[0],$i,1);
$pic.="img src="timex/$digit.gif" width="15" height="20"";
}
?
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
html
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
title3种计数器/title
style type="text/css"
!--
.style1 {
font-size: 24px;
color: #00FF99;
}
.style2 {color: #FF00FF}
.style3 {color: #CC0033}
.style4 {color: #0000FF}
.style5 {color: #FF0000}
.style6 {
font-size: 36px;
color: #996633;
}
--
/style
/head
body
div align="center" class="style1 style6"枫树林下
/div
div align="center"
p class="style1" /p
p class="style1" /p
p class="style1"span class="style3"总共有/span?=$row[0]; ?span class="style5"人/spanspan class="style4"来过/spanspan class="style2"这个网站
/span/p
p class="style1"span class="style3"总共有/span?=$row[0]; ?span class="style5"人/spanspan class="style4"来过/spanspan class="style2"?=$user?网站/span/p
p class="style1"?=$pic?/p
/div
/body
/html
来源:http://www.tulaoshi.com/n/20160219/1601345.html
看过《php计数器的设计与实现》的人还看了以下文章 更多>>