All pastes #49225 Raw Edit

captcha.php

public php v1 · immutable
#49225 ·published 2006-04-12 23:16 UTC
rendered paste body
<?phpsession_start();function strrand($length){        $str = "";        while(strlen($str)<$length){        $random=rand(48,122);        #if( ($random>47 && $random<58)  ){        if (ereg('[A-Za-z]',chr($random)))                $str.=chr($random);        #}        }        return $str;}$word = $_SESSION['tx_captcha_string'] = strrand(5);$im = imagecreate(150, 40); // Create new 150 x 40 image// Set colors for image$background_color = imagecolorallocate($im, 255, 255, 255);$text_color = imagecolorallocate($im, 0, 0, 0);$line = imagecolorallocate($im, 201, 201, 201);//$circle = imagecolorallocate($im, 193, 224, 231);$circle = imagecolorallocate($im, 255, 197, 0);if($word){   while($obj['ell']<5){   // Draw ellipse in background   imagefilledellipse($im,rand(10,140),rand(5,38),rand(20,60),rand(5,35),$circle);   ++$obj['ell']; // Increment ellipse count   }        while($obj['lines']<10){                                                                        // Draw line in background                                                                        imageline($im,rand(1,150),rand(1,20),rand(1,150),rand(30,40),$line);                                                                        ++$obj['lines']; // Increment line count                                                                  }   $letters = preg_split("//",$word); // Split secret word into letters   $cur_x = 5; // Start x location of letters   foreach($letters as $value){ // Loop for all letters     $cur_x = rand(10,20) + $cur_x;     imagestring($im,rand(4,5),$cur_x,rand(10,18),$value,$text_color); // Put letter on image       }        }else{        // Put error on image        imagestring($im, 5, 55, 5, "Error!", $text_color);        imagestring($im, 5, 10, 20, "Reload the page!", $text_color);        }        // Draw border around image        imageline($im, 0, 0, 149, 0, $text_color); // Top horizontal        imageline($im, 0, 0, 0, 39, $text_color); // Left vertical        imageline($im, 149, 0, 149, 39, $text_color); // Right vertical        imageline($im, 0, 39, 149, 39, $text_color); // Bottom horizontal        header("Content-type: image/gif"); // Set display mode as PNG        imagegif($im); // Display image        imagedestroy($im); // Delete image from memory cache //header("Content-type: image/png");//imagepng($img_number);?>