Captcha Images, how to make captacha image? |
||
Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.
In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.
Zymic Webmaster Forums Web Design & Development Server Side Scripting PHP |
||
![]() |
Captcha Images, how to make captacha image? |
||
Aug 27 2008, 04:02 AM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 9 Joined: 27-August 08 Member No.: 56,961 |
i am trying to make captcha image for my registration account
heres the code <?php session_start(); class CaptchaSecurityImages { var $font = 'monofont.ttf'; function generateCode($characters) { /* list all possible characters, similar looking characters and vowels have been removed */ $possible = '123456789bcdfghjkmnpqrstvwxyz'; $code = ''; $i = 0; while ($i < $characters) { $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); $i++; } return $code; } function CaptchaSecurityImages($width='120',$height='40',$characters='6') { $code = $this->generateCode($characters); $_SESSION['security_code'] = $code; /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } /* generate random lines in background */ for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function'); /* output captcha image to browser */ imagejpeg($image); imagedestroy($image); } } $width = isset($_GET['width']) ? $_GET['width'] : '220'; $height = isset($_GET['height']) ? $_GET['height'] : '40'; $characters = isset($_GET['characters']) ? $_GET['characters'] : '8'; header('Content-Type: image/jpeg'); $captcha = new CaptchaSecurityImages($width,$height,$characters); ?> but the following error is coming <br /> <b>Fatal error</b>: Call to undefined function imageTTFBbox() in /finall/users/CaptchaSecurityImages.php</b> on line <b>38</b><br /> i dont understand why this fuction is undefined!! am using php5 ! |
|
|
Aug 27 2008, 04:15 AM
Post
#2
|
|
![]() Hosting Abuse Staff ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Moderators Posts: 2,933 Joined: 14-February 08 From: Fort Myers FL, USA Member No.: 10,089 |
Quote from php.net
QUOTE Note: This function requires both the GD library and the » FreeType library. I don't know if FreeType is installed on Zymic servers. |
|
|
Aug 27 2008, 04:19 AM
Post
#3
|
|
|
Newbie ![]() Group: Members Posts: 9 Joined: 27-August 08 Member No.: 56,961 |
any alernatives???
|
|
|
Aug 27 2008, 04:29 AM
Post
#4
|
|
![]() Hosting Abuse Staff ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Moderators Posts: 2,933 Joined: 14-February 08 From: Fort Myers FL, USA Member No.: 10,089 |
Quick google search returned this
http://www.codewalkers.com/c/a/Miscellaneo...PTCHA-with-PHP/ It uses part of a randomly generated md5 string. Doesn't use any font of your own. Although this may not be what you wanted, it should work. I haven't tested it on Zymic servers, but looking over the code pretty quick seems like it should. |
|
|
Aug 27 2008, 05:03 AM
Post
#5
|
|
|
Newbie ![]() Group: Members Posts: 9 Joined: 27-August 08 Member No.: 56,961 |
thanks buddy for the qucik search now i just changed my code like that
<?php session_start(); class CaptchaSecurityImages { var $font = 'monofont.ttf'; function generateCode($characters) { /* list all possible characters, similar looking characters and vowels have been removed */ $possible = '123456789bcdfghjkmnpqrstvwxyz'; $code = ''; $i = 0; while ($i < $characters) { $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); $i++; } return $code; } function CaptchaSecurityImages($width='120',$height='40',$characters='6') { $code = $this->generateCode($characters); $_SESSION['security_code'] = $code; /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 0, 0, 0); $text_color = imagecolorallocate($image,233,239,239); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } hear i changed the code imagestring($image,2,40,10,$code,$text_color); imagejpeg($image); imagedestroy($image); } } $width = isset($_GET['width']) ? $_GET['width'] : '220'; $height = isset($_GET['height']) ? $_GET['height'] : '40'; $characters = isset($_GET['characters']) ? $_GET['characters'] : '8'; header('Content-Type: image/jpeg'); $captcha = new CaptchaSecurityImages($width,$height,$characters); ?> and works perfectly !!!!!!!!!!!!!! happy endings http://egraduate.vndv.com/finall/users/singin_employes.php |
|
|
Aug 27 2008, 05:50 AM
Post
#6
|
|
![]() Hosting Abuse Staff ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Moderators Posts: 2,933 Joined: 14-February 08 From: Fort Myers FL, USA Member No.: 10,089 |
Man that is one serious captcha. Thats the smallest letters i've ever seen, but I guess that could stop a robot from figuring it out.
Just so you know you spelled signin wrong. I don't think you meant singin. Also you spelled work, Wrok in Work Phone. How Did You Hear about us: In Magazin should be In Magazine. And Verification you spelled Varification. |
|
|
![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users) |
||
| 0 Members: | ||
Forum Jump |
||
| Lo-Fi Version | Time is now: 24th May 2013 - 11:40 PM |