name : class.Captcha.php--
<?php
#------------------------------------------------------------------------------------------------------------------------------------------
#	Programmer  : Sirichai Teerapattarasakul
#	NickName : TaTump
#	Email : tump_si@yahoo.com
#	Msn : tump_si@hotmail.com
#	Website : http://www.memo8.com
#------------------------------------------------------------------------------------------------------------------------------------------

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("captcha.jpg");
        $bg = imagecolorallocate($im, 0, 0, 0);
        $bordercolor = imagecolorallocate($im, 0, 0, 0);
        $fontcolor = imagecolorallocate($im, 255, 255, 255);
        imagerectangle($im,0, 0, $width-1, $height-1, $bordercolor);
        $font = imageloadfont("anonymous.gdf");
        imagestring($im, $font , $this->size, 5, $string, $fontcolor);
        imagecopymerge($im, $imBG, 0, 0, rand(1,50), 0, 256, 256, 55);
        imagepng($im);
        imagedestroy($im);
    }
}
?>

© 2024 UnknownSec