|
<? # ปรับปรุง : 2548-11-27 (เริ่มเผยแพร่) # counter.php คือ ตัวนับเฉพาะหน้า อย่างง่าย ด้วยรหัสต้นฉบับไม่ถึงคืบ # โปรแกรมนี้เริ่มพัฒนาในโปรแกรม thaiabc__.exe และเผยแพร่ในเว็บไซต์ thaiabc.com # # วิธีใช้ # 1. โปรแกรมนี้ชื่ออะไรก็ได้ เช่น counter.php hit.php or .. # 2. ข้อมูลจะเป็นไปตามชื่อโปรแกรม แต่มี _ นำหน้า เช่น _counter.php หรือ _hit.php เป็นต้น # 3. ทดสอบใน Linux พบปัญหา Permission จึงต้องสร้าง _counter.php เป็นแฟ้มเปล่า แล้วส่งเข้าไป ด้วย FTP # 4. กำหนดสิทธิการเข้าถึงแฟ้ม ให้ chmod 777 สำหรับแฟ้มข้อมูล # 5. เพิ่ม <img src=counter.php> ลงในแฟ้ม html ที่ต้องการใช้ # =================== # Color Properties $c_font{0} = 255; // Red $c_font{1} = 255; // Green $c_font{2} = 255; // Blue $bg_font{0} = 0; // Red $bg_font{1} = 0; // Green $bg_font{2} = 255; // Blue # =================== $x = split("/",$_SERVER["SCRIPT_NAME"]); $y = $x[count($x) - 1] . "_"; header("Content-type: image/png"); if (file_exists("$y")) { $FILE=fopen ("$y","r"); $num=fgets($FILE,10); $num = $num + 1; fclose ($FILE); } else { $num = 1; } $FILE=fopen ("$y","w"); fputs ($FILE,$num); fclose ($FILE); $num = str_repeat("0",(6 + -1 - floor(log10($num)))).$num; $font = 4; $width = 60; $height = 16; $im = @imagecreate ($width,$height); $color_font = ImageColorAllocate($im, $c_font{0}, $c_font{1}, $c_font{2}); $color_bg = ImageColorAllocate($im, $bg_font{0}, $bg_font{1}, $bg_font{2}); imagefill($im, 0, 0, $color_bg); imagestring ($im, $font, 5, 0, $num, $color_font); imagepng ($im); imagedestroy($im); ?> |