php计数器的设计与实现

?phpphp 留言板防刷新作用 $ip = $_SERVER[‘REMOTE_ADDR’]; $conn =
mysql_connect($mysql_server_name, $mysql_username,
$mysql_password); $sql = SELECT * FROM `my_counter` WHERE ip =
‘$ip’; mysql_select_db($mysql_database, $conn); $result =
mysql_query($sql); $row = mysql_fetch_row($result); print_r($row);
if(!$rowState of Qatar //如果IP未有现身过就新扩张 { $sql = INSERT INTO `my_counter`
( `new`, `ip`, `time_at`) VALUES (‘1’, ‘$ip’, NOW()); $result =
mysql_query($sql); } else //如果IP出现过 { $sql = SELECT TIME_TO_SEC(
NOW( ) ) – TIME_TO_SEC( time_at ) FROM `my_counter` WHERE `ip` =
‘$ip’ORDER BY `TIME_TO_SEC( NOW( ) ) – TIME_TO_SEC( time_at )`
ASC ; $result = mysql_query($sql); $row = mysql_fetch_row($result);
print_r($row); if($row[0]5卡塔尔国 //借使IP现身过,则看他有未有超过常规5秒 {
$sql = INSERT INTO `my_counter` ( `new`, `ip`, `time_at`)
VALUES (‘1’, ‘$ip’, NOW()); $result = mysql_query($sql); } } $sql =
SELECT COUNT(*) FROM `my_counter`; $result = mysql_query($sql);
$row = mysql_fetch_row($result); print_r($row);
mysql_free_result($result); mysql_close($conn);?

本程序有4个流量计。
index.php是四个见惯司空的流速计能够看见总次数和哪些人来那么些站点的次数,点两回加若干次,不防水。
index1.php也是二个防水的流量计可以看来次数和哪些人来那些站点的次数,点三遍加若干遍,防水,5秒加贰回。
index2.php是一个防水的计数器能够见见总次数和哪些人来以此站点的次数,点一次加四遍,防水,2秒加二遍。
indexa.php是二个家常和防水和图纸的计数器3合生龙活虎的。可以见到总次数和哪些人来这几个站点的次数,防水,有图表。
关键语句:
防水的:$sql=”SELECTCOUNT(*)FROM`counter_1`WHEREuser=’$user’ANDTIME_TO_SEC(NOW()-`time`)5ANDip=’$REMOTE_ADD本田CR-V'”;
图形计数器:for($i=0;$istrlen($row[0]);$i++) {
$digit=substr($row[0],$i,1);
$pic.=”imgsrc=/”timex/$digit.gif/”width=/”15/”height=/”20/””; }

?//——[ 基本设定 ]——-$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($row1State of Qatar;//撤废查询结果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”
“”htmlheadmeta “Content-Type” content=”text/html;
charset=gb2312″title3种流速計/titlestyle 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

bodydiv align=”center” 枫树林下/divdiv align=”center” p /p p /p p span
总共有/span?=$row1[0]; ?span 人/spanspan 来过/spanspan 这么些网址/span/p
p span 总共有/span?=$row2[0]; ?span 人/spanspan 来过/spanspan
?=$user?网站 /span /p/div/body/html

发表评论

电子邮件地址不会被公开。 必填项已用*标注