Posted 18 January 2009 - 10:17 AM
I've been reading through the book and following the code now without testing it. I have Apache and MySQL 5 and PHP 5 on both a linux and vista machine.
I finally decided to load some code onto my servers to test it out, and I can't get it to work on either server. I even got a free account at byethost.com that has needed extensions enabled, but it's not working there either.
I just want to produce the PNG file on the fly via PHP but the page either comes back blank or with an error. There's really no way of tracing the code for debugging, but I'm wondering if anyone got this code working.
I notice in the download of Chapter 11 pg. 623 code that it calls function SHA for encryption, but in the book it has it typed out as SHA1. I changed it to call SHA1 because I was crashing on that statement, but now I can't get the code to go much further. Has anyone produced a PNG via PHP?
I went through the appendix to make sure I had the needed extensions loaded. I take it that the code uploaded to the server had been tested, so I must have something in my configuration wrong. Has anyone else had a problem with this or any of the other scripts? Any feedback to get this working is much appreciated.
EDIT: I get an error message that reads:
"The image "http://localhost/ch11/page623/captcha.php" cannot be displayed because it contains errors."
I noticed that this message is not text, but it is an image. So I'm getting an image, just not the CAPTCHA one I generate.
RESOLVED:
I looked back at the code to see what could be causing the error, and I figured it out. I noticed the call:
imagettftext($img, 18, 0, 5, CAPTCHA_HEIGHT - 5, $text_color, 'Courier New Bold.ttf', $pass_phrase);
This is trying to reference the TTF file directly, and out of curiosity I just googled the font name, downloaded the file and put it in the same folder as my script. I refreshed my browser, and there was my image.
EDIT:
Well it worked on the Windows server, and not the linux server. The linux server generated an image, but without text. I realize that linux is fussy about case sensitivity, so I had to edit the capital letters in the php script to match the file name exactly.
I had it calling "Courier New Bold.ttf" and my file name was "Courier new Bold.ttf"" Notice the change in case in the word "new". When I matched them exaclty, the linux server loaded the file properly.
Also, make sure to call SHA1, not SHA as the script file is now saved as on the Head First server while I write this. They may fix that in the future so the code works. I also wish they would include the font file in the download so it works without these edits, but there might be copyright issues with that not allowing them.