$width = 145; $height = 45; $authcode = Vcaptcha_read_code (' words.txt '); $BG = ' bg/captcha_bg3.jpg '; $img _type = ' png '; /* Verification Code length */ $letters = strlen ($authcode); $img _BG = (function_exists (' Imagecreatefromjpeg ') && ((Imagetypes () & Img_jpg) > 0))? Imagecreatefromjpeg ($BG): Imagecreatefromgif ($BG); $BG _width = imagesx ($img _bg); $BG _height = Imagesy ($img _bg); $img _org = ((function_exists (' Imagecreatetruecolor ')) && php_version >= ' 4.3 ')? Imagecreatetruecolor ($width, $height): Imagecreate ($width, $height); /* Copy the original image and resize the background image */ if (function_exists (' imagecopyresampled ') && php_version >= ' 4.3 ')//GD 2.x { Imagecopyresampled ($img _org, $img _bg, 0, 0, 0, 0, $width, $height, $bg _width, $BG _height); } else//GD 1.x { Imagecopyresized ($img _org, $img _bg, 0, 0, 0, 0, $width, $height, $bg _width, $BG _height); } Imagedestroy ($img _BG); $CLR = Imagecolorallocate ($img _org, 255, 255, 255); /* Draw Border */ Imagerectangle ($img _org, 0, 0, $width-1, $height-1, $CLR); /* Get the height and width of the verification code */ $x = ($width-(Imagefontwidth (5) * $letters))/2; $y = ($height-imagefontheight (5))/2; Imagestring ($img _org, 5, $x, $y, $authcode, $CLR); Header (' Expires:thu, 1970 00:00:00 GMT '); http/1.1 Header (' Cache-control:private, No-store, No-cache, Must-revalidate '); Header (' Cache-control:post-check=0, pre-check=0, max-age=0 ', false); http/1.0 Header (' Pragma:no-cache '); if ($img _type = = ' jpeg ' && function_exists (' imagecreatefromjpeg ')) { Header (' Content-type:image/jpeg '); Imageinterlace ($img _org, 1); Imagejpeg ($img _org, FALSE, 95); } Else { Header (' content-type:image/png '); Imagepng ($img _org); } Imagedestroy ($img _org); function Vcaptcha_read_code ($wordlist _file) { $fp = @fopen ($wordlist _file, ' RB '); if (! $fp) return false; $fsize = filesize ($wordlist _file); if ($fsize <) return false; Too small of a list to be effective if ($fsize < 128) { $max = $fsize; Still pretty small but changes the range of seeking } else { $max = 128; } Fseek ($FP, rand (0, $fsize-$max), seek_set); $data = Fread ($fp, 128); Read a random bytes from file Fclose ($FP); $data = Preg_replace ("/r?n/", "n", $data); $start = Strpos ($data, "n", rand (0, 100)) + 1; Random Start position $end = Strpos ($data, "n", $start); Find end of Word Return Strtolower (substr ($data, $start, $end-$start)); Return substring in bytes } |