Home >Backend Development >PHP Tutorial >Design and Implementation of PHP Counter Page 1/2_PHP Tutorial

Design and Implementation of PHP Counter Page 1/2_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 16:12:06803browse

本程序有4个计数器。
index.php是一个普通的计数器可以看出总次数和哪个人来这个站点的次数,点几次加几次,不防水。
index1.php也是一个防水的计数器可以看出次数和哪个人来这个站点的次数,点几次加几次,防水,5秒加一次。
index2.php是一个防水的计数器可以看出总次数和哪个人来这个站点的次数,点几次加几次,防水,2秒加一次。
indexa.php是一个普通和防水和图形的计数器3合一的。可以看出总次数和哪个人来这个站点的次数,防水,有图形。


关键语句:
防水的:$sql = "SELECT COUNT(*) FROM `counter_1` WHERE user='$user' AND TIME_TO_SEC(NOW()-`time`) < 5 AND ip='$REMOTE_ADDR'";
图形计数器: for ( $i=0; $i< strlen($row[0]);$i++)
{
$digit= substr($row[0],$i,1);

$pic.="";
       }


//------[ 基本设定 ]-------
$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);
?>

 






3种计数器


枫树林下




TotalPeopleVisitedthis website

TotalPeopleVisitedWebsite

        





www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313749.htmlTechArticleThis program has 4 counters. index.php is an ordinary counter that can show the total number of times and the number of times a person has visited this site, plus the number of clicks and the number of clicks. It is not waterproof. index1.php is also a defense...
Statement:
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