zhinigami Posted January 24, 2008 Share Posted January 24, 2008 hi all, I have tried download some example of captcha example for image validation like http://www.phpclasses.org/browse/package/3193.html or http://www.digitalmidget.com/php_noob/captcha.php But i still failed to successfully test it. I want to try to create it in a registration form which can be well function in both IE and Firefox. The sample i got from above can not view in IE or Firefox. the image didn't display out. I think it maybe caused by gd2_lib not be enabled? but I have found it is included in php.ini. Can i have someone's guide about this? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/87507-image-verification-for-registration-form-help/ Share on other sites More sharing options...
GingerRobot Posted January 24, 2008 Share Posted January 24, 2008 To check to see if the gd library is installed, run a script with this in: <?php phpinfo(); ?> You should find a section titled, GD. You may find that you have an old version running, or perhaps you have don't have FreeType support, which may well be required for the above examples. An alternative way of debugging the captcha scripts is to take out the lines which are similar to: header("Content-type: image/png"); imagepng($im); And add in the following lines, at the top of the script ini_set('display_errors','On'); error_reporting(E_ALL); Then navigate directly to the captcha script in your browser, and see if there are any errors being produced. Quote Link to comment https://forums.phpfreaks.com/topic/87507-image-verification-for-registration-form-help/#findComment-447603 Share on other sites More sharing options...
zhinigami Posted January 24, 2008 Author Share Posted January 24, 2008 Thanks for the guideline, I have checked with phpinfo(), my current php version is 5.2.3 and I only found this: Configure Command: cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" which is related to gd. Am i correct with this code in captcha_image.php? <?php session_start(); include("captcha_config.php"); // file with configuration data ini_set('display_errors','On'); error_reporting(E_ALL); // create random character code for the captcha image $text = ""; $key_chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; // 0 1 O I removed to avoid confusion $rand_max = strlen($key_chars) - 1; for ($i = 0; $i < $length; $i++) { $rand_pos = rand(0, $rand_max); $text.= $key_chars{$rand_pos}; } $_SESSION['captcha'] = $text; // save what we create // center text in the 'box' regardless of rotation function imagettftext_cr(&$img, $size, $angle, $x, $y, $content_color, $font, $text) { // retrieve boundingbox $bbox = imagettfbbox($size, $angle, $font, $text); // calculate deviation $dx = ($bbox[2]-$bbox[0])/2.0 - ($bbox[2]-$bbox[4])/2.0; // deviation left-right $dy = ($bbox[3]-$bbox[1])/2.0 + ($bbox[7]-$bbox[1])/2.0; // deviation top-bottom // new pivotpoint $px = $x-$dx; $py = $y-$dy; return imagettftext($img, $size, $angle, $px, $py, $content_color, $font, $text); } // get background image dimensions $imgsize = getimagesize($background); $height = $imgsize[1]; $width = $imgsize[0]; $xmax = $width - $sizex; $ymax = $height - $sizey; // create the background in memory so we can grab chunks for each random image $copy = imagecreatefromjpeg($background); // create the image $img = imagecreatetruecolor($sizex,$sizey); $content_color = imagecolorallocate($img, $red, $green, $blue); // choose a random block (right size) of the background image $x0 = rand(0,$xmax); $x1 = $x0 + $sizex; $y0 = rand(0,$ymax); $y1 = $y0 + $sizey; imagecopy($img,$copy, 0, 0, $x0, $y0, $x1, $y1); $angle = $random * (5*rand(0, - 20); // random rotation -20 to +20 degrees // add text to image once or twice (offset one pixel to emulate BOLD text if needed) imagettftext_cr($img, $size, $angle, $sizex/2, $sizey/2-$yofs, $content_color, $font, $text); if ($bold==1) { imagettftext_cr($img, $size, $angle, $sizex/2+1, $sizey/2-$yofs, $content_color, $font, $text); } //header ("content-type: image/png"); //imagepng ($img); imagedestroy ($img); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87507-image-verification-for-registration-form-help/#findComment-447616 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.