O'Reilly Forums: RESOLVED: Chapter 11 Source page 623 - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

RESOLVED: Chapter 11 Source page 623

#1 User is offline   cxb450 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 16
  • Joined: 18-January 09
  • Location:Pennsylvania

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.
0

#2 User is offline   ilario 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 23-March 09

Posted 23 March 2009 - 12:36 AM

Thanks for this post. To get captcha.php to work on my Vista dev machine indeed I made the changes you suggested:
- Replace "SHA" with "sha1"
- Copy the font to the same directory as the script and ensure the filename is "Courier New Bold.ttf"

Cheers
0

#3 User is offline   John Hindinger 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 13-March 09
  • Gender:Male
  • Location:Detroit
  • Interests:Career Transition: <br /><br />Proven leader from the energy, medical device, and technology fields qualified at the director and business unit executive levels; MS Electrical Engineering Rensselaer Polytechnic (RPI), BS Systems Engineering US Naval Academy, Nuclear Licensed, MBA University of Chicago, Licensed PE, French fluency.

Posted 05 April 2009 - 02:24 PM

This post helped me since I was having the same problem, but I'm still stumped on CAPTCHA.

I'm getting no part of the image to show up. I was able to verify the random text (echoed $pass_phrase to make sure the text was being randomly generated). But as far as any portion of the image, nothing appears. Any ideas?

I also couldn't find Courrier New Bold for free and tried plain old Courrier.tff and something called KochRoman.tff just to try it out. I obviously couldn't get far enough to test the type of text, but I thought I'd mention it in case my choice of fonts is corrupting the image.

Help!
Thank you
0

#4 User is offline   iceebananas 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 10-October 09

Posted 23 November 2009 - 08:56 PM

I had the same problem - and now it works! Thanks for posting a solution (I would have never figured that was the problem!)
0

#5 User is offline   ricechex 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 18
  • Joined: 02-July 09

Posted 31 March 2010 - 08:31 PM

QUOTE (iceebananas @ Nov 23 2009, 08:56 PM) <{POST_SNAPBACK}>
I had the same problem - and now it works! Thanks for posting a solution (I would have never figured that was the problem!)


Me too, same problem. I changed SHA to sha1 and it mentions on the bottom of page 355, right corner question, that sha1 is used if you need encryption within php bc you don't need a query/db for it.

And once i uploaded the font as well, it worked as expected.
0

#6 User is offline   kingnavneet 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 21-June 11

Posted 21 June 2011 - 04:16 AM

I am also having same problem on byethost yhe font is not loading.. please help
0

#7 User is offline   rhender 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 10
  • Joined: 13-August 12

Posted 02 September 2012 - 03:24 PM

I ran into this problem as well today.

I changed SHA to SHA1 on line 16 of captcha.php, and the the captcha image appeared, right after that one simple change.

Why do they use SHA1 here instead of just SHA? And why does that solve the problem?

I thought that earlier in the book they were using SHA for encryption... not SHA1 ???

Anyway, I'm glad it's solved. And if you are having problems with the font, it ("Courier New Bold.ttf") is in the files that you download from the head first site.

You just copy the font file (.ttf) onto the same directory level as the captcha.php file and it should work just fine. Glad I found this!

This post has been edited by rhender: 02 September 2012 - 03:25 PM

0

#8 User is offline   nyer4life 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 21-November 12

Posted 21 November 2012 - 10:20 AM

Thank you! I was about to pull my hair out :D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users