ผมโหลด captcha จาก ลิงค์นี้ลองเล่นดู http://www.memo8.com/lab/php/captcha/captcha.rar แต่รูปไม่ขึ้น ไม่ทราบว่าผิดพลาดตรงไหน ใครทราบช่วยแนะนำหน่อยครับ
รูปตอนรันครับ

โค้ดครับ
demo.html
Code
<IMG SRC="captcha.php" BORDER="0">
<FORM METHOD="POST" ACTION="demo.php">
<INPUT TYPE="text" NAME="strCheck">
<INPUT TYPE="submit">
</FORM>
captcha.php
Code
<?php
session_start();
include "class.captcha.php";
$capchar = new Captcha();
$capchar->size = 4; // ¨Ó¹Ç¹ÍÑ¡¢ÃÐ
$capchar->session="sCaptcha"; // ª×èÍ Session
$capchar->display();
?>
class.captcha.php
Code
<?php
ob_start();
class Captcha{
var $size;
var $session;
function randStr(){
$chars = 'abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
for ($i = 0; $i < $this->size; $i++){
$pos = rand(0, strlen($chars)-1);
$string .= $chars{$pos};
}
$_SESSION[$this->session] = $string;
return $string;
}
function display(){
$width = 26*$this->size;
$height = 50;
$string = $this->randStr();
$im = ImageCreate($width, $height);
$imBG = imagecreatefromjpeg("images/captcha.jpg");
$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$grey = imagecolorallocate($im, 170, 170, 170);
imagerectangle($im,0, 0, $width-1, $height-1, $grey);
$font = imageloadfont("font/anonymous.gdf");
imagestring($im, $font , $this->size, 5, $string, $black);
imagecopymerge($im, $imBG, 0, 0, 0, 0, 256, 256, 55);
imagepng($im);
imagedestroy($im);
}
}
?>
Tag : PHP, HTML/CSS