Last modified: 15. March 2004 Copyright (C): 2003, 2004 Pascal Rehfeldt, all rights reserved * GNU General Public License (Version 2, June 1991) * * This program is free software; you can redistribute * it and/or modify it under the terms of the GNU * General Public License as published by the Free * Software Foundation; either version 2 of the License, * or (at your option) any later version. * * This program is distributed in the hope that it will * be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public License * for more details. Description: This class can generate CAPTCHAs, see README for more details! Get the "Hurry up!" Font for the Captcha and save it in the same directory as this file. "Hurry up!" Font (c) by Andi See http://www.1001fonts.com/font_details.html?font_id=2366 ******************************************************************/ class captcha { var $Length; var $CaptchaString; var $ImageType; var $Font; var $CharWidth; function captcha ($length = 5, $type = 'png') { $this->Length = $length; $this->ImageType = $type; $this->Font = './hurryup.ttf'; $this->CharWidth = 27; $this->StringGen(); } function Showcaptcha() { $this->SendHeader(); $this->MakeCaptcha(); } function StringGen () { $uppercase = range('A', 'Z'); $numeric = range(0, 9); $CharPool = array_merge($uppercase, $numeric); $PoolLength = count($CharPool) - 1; for ($i = 0; $i < $this->Length; $i++) { $this->CaptchaString .= $CharPool[mt_rand(0, $PoolLength)]; } } function SendHeader () { switch ($this->ImageType) { case 'jpeg': header('Content-type: image/jpeg'); break; case 'png': header('Content-type: image/png'); break; default: header('Content-type: image/png'); break; } } function MakeCaptcha () { $imagelength = $this->Length * $this->CharWidth + 16; $imageheight = 37; $image = imagecreate($imagelength, $imageheight); $bgcolor = imagecolorallocate($image, 146, 176, 212); $stringcolor = imagecolorallocate($image, 0, 0, 155); $linecolor = imagecolorallocate($image, 0, 0, 0); imagettftext($image, 25, -4, 8, 25, $stringcolor, $this->Font, $this->CaptchaString); imagecolortransparent($image,$bgcolor); switch ($this->ImageType) { case 'jpeg': imagejpeg($image); break; case 'png': imagepng($image); break; default: imagepng($image); break; } } function GetCaptchaString () { return $this->CaptchaString; } } // ************ Fim da Classe ************************* //Cria o CAPTCHA( gera o string e a imagem ... $GLOBALS['captcha'] = new captcha; // Guarda o string do captcha na session... session_id($_REQUEST['xsid']); session_start(); $_SESSION['CAPTCHAString'] = $GLOBALS['captcha'] ->GetCaptchaString(); // Vai exibir a imagem do captcha... $GLOBALS['captcha'] ->Showcaptcha(); ?>