一個簡單的圖形計數器

來源:互聯網
上載者:User
關鍵字 一個簡單的圖形計數器
需要MySQL,GD的支援,linux下php4RC1通過,這也是我做的系統中正在用的。
/***
hit_count表只一個欄位hit_count
page_visit_record表是用來控制一個ip一天內只產生一個計數器跳動
CREATE TABLE page_visit_record (
  visit_time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
  remote_addr char(15) NOT NULL,
  visit_page char(60) NOT NULL,
  KEY visit_time (visit_time, visit_page),
  PRIMARY KEY (visit_time)
);
***/
include("config.inc.php3");
$query="select count(*) as tong from page_visit_record where remote_addr='$REMOTE_ADDR' and date_format(visit_time,'%Y-%m-%d')=curdate()";
$result=@mysql_query($query,$dbconnect);
$has_count=@mysql_result($result,0,"tong");
@mysql_query("lock tables hit_count write",$dbconnect);
$query="select * from hit_count";
$result=@mysql_query($query,$dbconnect);
if(@mysql_num_rows($result)>0){
  $cur_count=@mysql_result($result,0,"hit_count");
  if($has_count==0){
    $cur_count++;
    $query="update hit_count set hit_count='$cur_count'";
    @mysql_query($query,$dbconnect);
  }
  @mysql_query("unlock tables",$dbconnect);
}
else{
  $cur_count=1;
  $query="insert into hit_count (hit_count) values ('$cur_count')";
  @mysql_query($query,$dbconnect);
  @mysql_query("unlock tables",$dbconnect);
}
while(strlen($cur_count)<8)
  $cur_count="0$cur_count";

$visit_time=date("Y-m-d H:i:s");
$query="insert into page_visit_record (visit_time,remote_addr,visit_page) values ('$visit_time','$REMOTE_ADDR','$page')";
@mysql_query($query,$dbconnect);

Header("Content-type: image/gif");
$im = imagecreate(56,16);
$black = ImageColorAllocate($im, 0,0,0);
$blue = ImageColorAllocate($im, 0,0,255);
$white = ImageColorAllocate($im, 255,255,255);
$yellow = ImageColorAllocate($im, 255,255,0);
imagerectangle($im, 0, 0, 54, 14, $blue);
//imagestring($im, 2, 4, 1, $cur_count, $yellow);
imagestring($im, 2, 4, 1, $cur_count, $yellow);
ImageGif($im);
ImageDestroy($im);

?>


  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.