Captcha.php
<?php

    class Captcha{
        var $width = 150;
        var $height = 80;
        var $password;
        var $length;

        function Captcha( $length = 5 ){
            $this->setLength( $length );
            $this->random();
        }
        function setLength( $length ){
            $this->length = intval( $length ) ;
        }
        function getLength(){
            return $this->length;
        }
        function setWidth( $width ) {
            $this->width = intval ( $width );
        }
        function getWidth(){
            return $this->width;
        }
        function setHeight( $height ) {
            $this->height = intval ( $height );
        }
        function getHeight(){
            return $this->width;
        }
        function getPassword(){
            return $this->password;
        }
        function random(){
            srand( ( double ) microtime() * 1000000 );
            $randomString = md5( rand( 0 , 9999 ) );
            $this->password = substr( $randomString , 0 , $this->length );
        }

        function getImage(){

            $png = ImageCreate(  $this->width  , $this->height );
            $backgroundColor = ImageColorAllocate( $png , 192 , 192 , 192 );
            $textColor = ImageColorAllocate( $png , 128 , 128 , 128 );
            ImageFill($png, 0, 0, $backgroundColor );

            $x = rand( 5 , $this->width - ( $this->length * 10 ) );
            $y = rand( 5 , $this->height - 20 );

            ImageString( $png , 5 , $x , $y , $this->password , $textColor );

            ImagePng($png);
            Imagedestroy($png);


        }

    }
?>
 
Hosted by www.Geocities.ws

1