yandoo Posted July 17, 2013 Share Posted July 17, 2013 Hiya I'm trying to get a captcha script to work but the images never appears. I've check out that the GD2 extension is enabled in wamp and also checked the php.ini file and can confirm extension=php_gd2.dll is without the semicolon so enabled. I'm following a tutorial and have the source code to test it so assume its something wrong with the installion of GD2? Any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
yandoo Posted July 17, 2013 Author Share Posted July 17, 2013 I've tested it on another webserver with gd_2 enabled and it still doesnt show the image, maybe theres a problem with the code? captcha.php <?php /* captcha.php file*/ session_start(); header("Expires: Tue, 01 Jan 2013 00:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i < 5; $i++) { $randomString .= $chars[rand(0, strlen($chars)-1)]; } $_SESSION['captcha'] = strtolower( $randomString ); $im = @imagecreatefrompng("captcha_bg.png"); imagettftext($im, 30, 0, 10, 38, imagecolorallocate ($im, 0, 0, 0), 'larabiefont.ttf', $randomString); header ('Content-type: image/png'); imagepng($im, NULL, 0); imagedestroy($im); ?> captcha-validate.php <?php /* captcha-validate file */ session_start(); if(strtolower($_POST['answer']) == $_SESSION['captcha']) echo 'Captcha solved sucesfully, now you can allow this user to submit comment/vote/upload/etc.'; else echo 'Sorry, captcha not solved. Offer user captcha again or what ever.'; ?> demo.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <title>Simple PHP captcha demo</title> <meta name="viewport" content="width=device-width; initial-scale=1.0" /> </head> <body> <div> <header> <h1>Simple PHP captcha demo</h1> </header> <div> <img src="captcha.php" /> <form action="captcha-validate.php" method="post"> <input type="text" name="answer" placeholder="Enter captcha here" /> <input type="submit" value="CHECK" /> <input type="button" onClick="window.location.href = window.location.href" value="Reload" /> </form> </div> <footer> <p> © Copyright by <a href="http://www.ivebe.com">Danijel Petrovic</a> </p> </footer> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Solution .josh Posted July 17, 2013 Solution Share Posted July 17, 2013 go directly to captcha.php and see if it outputs any errors. My guess is either captcha_bg.png and/or larabiefont.ttf doesn't exist in the dir your script is being run in. Quote Link to comment Share on other sites More sharing options...
yandoo Posted July 18, 2013 Author Share Posted July 18, 2013 (edited) Thank for your reply, your absolutely right, the font.ttf wasn't in the correct directory.. All is fine now. Thank you Edited July 18, 2013 by yandoo Quote Link to comment 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.