简单易用的计数器(数据库)

2016-01-29 14:37 26 1 收藏

简单易用的计数器(数据库),简单易用的计数器(数据库)

【 tulaoshi.com - PHP 】

  用法
<?
include("counter.php");
Counter(__FILE__);//为文件增加一个计数
if($PHP_SELF=="/index.php")
{
$count=Counter("INDEX_COUNT");//为首页增加一个计数
}
else
{
$count=Counter("INDEX_COUNT","",0);//取得首页计数
}
echo "你是第$count个访问者";
?
--------counter.php-----------
<?
if(!isset($PHP_INCLUDE_COUNTER_PHP))
{$PHP_INCLUDE_COUNTER_PHP=__FILE;

$counter_error_state=0;
$counter_error_msg="";
function Counter($file,$query="",$add=1)
{
        $db_name="database";
        $db_user="username";
        $db_pass="password";
        $db_table="counter";

        if(empty($file))
        {
                $counter_error_state=-100;
                $counter_error_msg="缺少第一个参数或参数为空";
                return -100;
        }
        global $PHP_SELF,$QUERY_STRING,$counter_error_state,$counter_error_msg;
        if(empty($db_user)||!$db_user||$db_user=="")$res=@mysql_connect("localhost");
        else $res=@mysql_connect("localhost",$db_user,$db_pass);
        if(!$res)
        {
                $counter_error_states=-10;
                $counter_error_msg="不能连接数据库";
                return -10;
        }
        if(!@mysql_select_db($db_name))
        {
                $counter_error_states=-11;
                $counter_error_msg="不能选择数据库";
                return -11;
        }
        else
        {
                if(!$db_res=@mysql_query("SELECT * FROM ".$db_table))
                {
                        if(!$db_res=@mysql_query("CREATE TABLE ".$db_table." (id INTEGER AUTO_INCREMENT,PRIMARY KEY (id),file VARCHAR(255),query VARCHAR(255),time VARCHAR(255),count INT)"))
                        {
                            &

来源:http://www.tulaoshi.com/n/20160129/1493763.html

延伸阅读
标签: Java JAVA基础
  import java.io.Serializable; public class Counter implements Serializable{ // Initialize the bean on creation int count = 0; // Parameterless Constructor public Counter() { } // Property Getter public int getCount() { // Increment the count property, with every request count++; return this.count; } // P...
标签: PHP
  --------------------------------------------------------------------------------   请保持文章的完整性   --------------------------------------------------------------------------------------   <?   //counter.php All rights reserved http://sports98.126.com   ...
标签: ASP
<% dim fso,f,no,I '定义变量绝对是个好习惯 Set fso = CreateObject("Scripting.FileSystemObject") '建立对象的实例 Set f = fso.OpenTextFile(Server.MapPath("count.no"), 1, True) '建立文本文件,打开为只读. if f.AtEndOfStream then '判断这个文件是否不存在 no=1 else no=f.ReadLine no=no+1 end if f.Close set f=fso.O...
标签: PHP
       <?php         $counterFile = "balong.txt";//存储数值的文件名几路径      function displayCounter($counterFile) {    $fp = fopen($counterFile,"rw");    $num = fgets($fp,5);    $num +...
标签: ASP
  以下介绍用数据库实现简单计数器 '下面存为count.asp <% Set conn=Server.CreateObject("ADODB.Connection") conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="& Server.MapPath("count.mdb") % <%on error resume next% <%sql="update count set hit=hit+1%<%conn.Execute(sql)% <%sql = "sele...

经验教程

974

收藏

54
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部