[982]PHP網站開發 進階應用技巧
<?php
$root_pass="12345"; //資料庫root密碼
$db_name="test"; //資料庫名稱
/* 連資料庫檢查 */
$link=mysql_connect("localhost","root",$root_pass); //資料庫連線
mysql_select_db("test");
mysql_query("SET NAMES 'utf8'"); //設定語系
error_reporting(0);
$today=date("Y-m-d");
if($_GET['op']=="all"){
$sql="select sum(`counter`) from `counter`";
$bg="bnr_40.gif";
$size=18;
$x=20;
$y=26;
}else{
$sql="select `counter` from `counter` where `day`='$today'";
$bg="bnr_35.gif";
$size=12;
$x=10;
$y=18;
}
$result=mysql_query($sql);
list($counter)=mysql_fetch_row($result);
$counter=sprintf("%07s",$counter);
header("Content-type: image/gif");
$im = @imagecreatefromgif($bg) or die("無法建立GD圖片");
$text_color = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, $size, 0 , $x, $y, $text_color,"D3Petitbitmapism.ttf",$counter);
imagegif($im);
imagedestroy($im);
?>