April 30, 201115 yr Hi, I have this captcha set up on my website form and since I have re-uploaded files the image is no longer visible, can somebody please confirm that this file plus the font is all I need in my root folder server side or am I missing something simple? <?php session_start(); class CaptchaSecurityImages { var $font = 'monofont.ttf'; function generateCode($characters) { $possible = '23456789bcdfghjkmnpqrstvwxyz'; $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); $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } 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); } $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'); header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; } } $width = isset($_GET['width']) ? $_GET['width'] : '120'; $height = isset($_GET['height']) ? $_GET['height'] : '40'; $characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6'; $captcha = new CaptchaSecurityImages($width,$height,$characters); ?> Thanks
April 30, 201115 yr Could be a number of things - Permissions issue - GD not installed on server - Error in script being output and causing image to malform Out of the three, I'm going to say it's likely to be the last one Try commenting out these two lines header('Content-Type: image/jpeg'); imagejpeg($image); and see if you get any errors showing. You could also check your error_log file to see if there are any errors appearing in there
April 30, 201115 yr Author Could be a number of things - Permissions issue - GD not installed on server - Error in script being output and causing image to malform Out of the three, I'm going to say it's likely to be the last one Try commenting out these two lines header('Content-Type: image/jpeg'); imagejpeg($image); and see if you get any errors showing. You could also check your error_log file to see if there are any errors appearing in there I commented out the above lines of code and re-uploaded, still nothing and there are no errors showing. I downloaded the image from the website, I have attached a screenshot of the message I received - the 'CaptchaSecurityImages.php' is server side so I am at a loss as to why this is saying differently!? Thanks
April 30, 201115 yr I can't see the problem, but I'd suggest you upgrade to ReCaptcha or an alternative. Captcha has been broken and doesn't not guard against spam anymore. ReCaptcha has an easy to use Class already made on their website. An alternative could be a Question/Answer challenge (eg, "What colour is the sky?" or "What is this website's name?").
April 30, 201115 yr Author I can't see the problem, but I'd suggest you upgrade to ReCaptcha or an alternative. Captcha has been broken and doesn't not guard against spam anymore. ReCaptcha has an easy to use Class already made on their website. An alternative could be a Question/Answer challenge (eg, "What colour is the sky?" or "What is this website's name?"). I found the captcha image was broken so that is working for now, however I will try re-captcha...thanks
Create an account or sign in to comment