justin7410 Posted April 16, 2013 Share Posted April 16, 2013 Hey guys, im trying to create a 'captcha' image for registration security for my site. currently i have 2 separate pages working together, my captcha.php file & my register.php now, what i am doing is trying to get a generate code that will be random and create an image with this string. this image will then be linked in the registration form where the user will have to match that random string image. sounds simple except , for some reason the code i have supplied from the tutorial is not outputting the image in the form. i have GD's installed on my server, and i have the font file saved also in the directory/ my code is : captcha.php <?session_start(); header('Content-type: image/jpeg'); $text = $_SESSION['secure']; $font_size = 30; $image_height = 200; $image_width = 40; $image = imagecreate($image_width, $image_height); imagecolorallocate($image, 255, 255, 255); // white $text_color = imagecolorallocate($image, 0, 0, 0); //black imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font.ttf', $text); imagejpeg($image); ?> so in this i have created the image captcha.php should now be a jpeg.. i then go to my register.php declare the $_SESSION and input the src="captcha.php'' register.php <?php include('include/init.php'); $_SESSION['secure'] = rand(1000,9999); ?> and the form : <tr> <td class="register_td_left2"><span class="">Security Code:</span></td> <td valign="middle" style="padding-left:2px"><input id="security_code" name="security_code" type="text" maxlength="4" size="5"></td> <td align="left" valign="middle"><img src="generate.php" alt="Your Security Code"></td> </tr> this is my first time adding a captcha and going through this process. the only thing i can think that would not be allowing it output the image, would be the 'font.tff' not properly working, or for some odd reason i dont have the GD functions installed correctly. any suggestions ? or ideas ? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 16, 2013 Share Posted April 16, 2013 Debug it. Go to the image directly, comment out the header, turn on error reporting and see what's wrong. Quote Link to comment Share on other sites More sharing options...
justin7410 Posted April 16, 2013 Author Share Posted April 16, 2013 Thanks Jessica, i did as you suggested , so what i have figured out so far is that i was getting a fatal error of : Fatal error: Call to undefined function imagettftext() in /home/justin/public_html/captcha.php on line 19 This made me think , hmmm maybe the GD function is not properly installed on my server and is not registering the image. i then went to my phpinfo() to see if GD was enabled as you can see it is installed and enabled. i then am wondering do i need to have FreeType library also installed and enabled ? i cant seem to find that in my phpinfo(). but im guessing this is the issue right here. any suggestions Quote Link to comment Share on other sites More sharing options...
Q695 Posted April 16, 2013 Share Posted April 16, 2013 I've used it years ago, and the image creator is supposed to be on its own page, as the browser will treat the code like a image not a page. When you go to the submit page it checks the code. Quote Link to comment Share on other sites More sharing options...
justin7410 Posted April 16, 2013 Author Share Posted April 16, 2013 hey Q, i am confused as to what you mean exactly, the code is on its own page, the page is then converted in to a different content type using the header function are you saying that the oen single line of code has to be on its own separate file ? Quote Link to comment Share on other sites More sharing options...
Q695 Posted April 16, 2013 Share Posted April 16, 2013 So you see the image, because I found that tricky when I first started out with the captcha? Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 i then am wondering do i need to have FreeType library also installed and enabled ? You're right. How did you enable GD2? Enabling GD2 enabled FreeType by default for me on both my Windows and Linux boxes. The configuration switch is explained here: http://us1.php.net/manual/en/image.installation.php Quote Link to comment Share on other sites More sharing options...
justin7410 Posted April 16, 2013 Author Share Posted April 16, 2013 You're right. How did you enable GD2? Enabling GD2 enabled FreeType by default for me on both my Windows and Linux boxes. The configuration switch is explained here: http://us1.php.net/manual/en/image.installation.php Gd was already installed and enabled by default, i never had to do anything, i am assuming that FreeType is not installed or enabled , simply because i can not find it in phpinfo. i dont want to ruin my server , any suggestions as to best install this ? i tried looking into my cpanel x to see if i can find the option: was told to go into the WHM > which i cant seem to find anywhere. Q695 Posted Today, 03:17 PM So you see the image, because I found that tricky when I first started out with the captcha? no the captcha comes as a missing image box on the form one thing i am wondering is also , i took a random font from my fonts folder. the font is an OTF file not TTF , i then changed the font file name from whatever it was to "font.ttf" and saved this into my web directory. i then refer to this file when i call the function imagettftext() , this should not be a problem right ? i still am very certain due to the fatal error i am getting, the library is not enabled correctly. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 16, 2013 Share Posted April 16, 2013 You can't just convert a font by changing the name. Quote Link to comment Share on other sites More sharing options...
justin7410 Posted April 16, 2013 Author Share Posted April 16, 2013 ok if i cant convert the font , does OTF.file work in the imagettftext() function ? my guess is no ? but it seems that most supported fonts are in OTF form. you guys know of any good sites to get free fonts with TFF ext ? regardless of the font file being improper, i still know that it has not even reached that point, due to the fatal error of the imagettftext() not even being able to be called. Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 17, 2013 Share Posted April 17, 2013 What type of server are you running? 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.