As I sat down to edit “Core Web Application Programming with PHP and MySQL”, I would sometimes find errors in the text so blindingly obvious and stupid that I would question whether or not I was truly qualified to write such a book. And yet, after talking with some other people who write books (and recalling days when I wrote huge amounts of code), it seems that this is all common and with much proof-reading and the hard work of some friendly reviewers, I was able to write a book of extremely high quality.
Of course, that just meant I would be even more devastated when the first technical errors WERE found in the book.
There have been a couple, but they’re not that killer serious.
Chapter 21 Error
In Chapter 21, where the book discusses writing your own output handler, the constant in the $_SESSION array to check is HTTP_ACCEPT_ENCODING, without the letter ‘S’ on the word accept.
The Accompanying Source Code
There are a couple of errors in the source code, the most glaring of which DID get fixed, but never made it on to the shipping CD ROM (d’oh!). In the SimpleBlog sample, in the file lib/entrymanager.inc, the class DBManager is accidentally misspelled DBMananager. Just fix it and change it back to the correct spelling and the sample will compile fine under PHP 5.0.x (x <= 4).
The other problem with the samples is that some new things have appeared in newer versions of PHP 5.0.y (y >= 5). PHP now defines a class called InvalidArgumentException, which conflicts directly with the class I have defined using the same name. The easy fix for this problem is to simply change the name of the class slightly, to something like MyInvalidArgumentException or some such thing.
To save you the hassle of tracking down and fixing all of these problems, I have put a new copy of the book source code up on the chipmunkninja.com servers. You can download these from here: phpwasrcupdate_2005-12-01.zip.
As always, if you see any other problems or errors in the book, or just want to comment on it, please feel free to drop me some mail.
I remain chagrined, but I’ll get over it.
236c235
< class NoEntrySpecified extends Exception
---
> class NoEntrySpecifiedException extends Exception
peace,
core
steve
But anyhow, this is a very good book that takes you from just writing and copying small code snippets to the lot. I would have liked a little more in chapter 29 & 30, but its just a minor thing.
Thank you for a serious good book.
Lars Jacobsen / Denmark
Parse error: syntax error, unexpected $end in /Library/WebServer/Documents/webapp/showprods.php on line 148
I can not get this program to work. It seems if you remove the echo <<<EOHTML... EOHTML code, the error is not there but you will not see the jpg files and html output.
What give?
After renaming it the class to MyDateTime, most of the problems went away.
I was using PHP Server version: 5.0.27-community
Any suggestions appreciated!
The best way to see what the errors are? Open up errors.inc and temporarily comment out the set_exception_handler() and set_error_handler() function calls. Then you'll see the messages right away.
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept
cookies.
Do you have updated code?
thanks,
Ganbold
I have php-5.2.x and index.php shows nothing.
When I access error.php?err=8 it shows following:
Unexpected Error
We are very sorry, but an unexpected error has occurred in the application. This occurs either because a page was used improperly and visited directly instead of through the web site or because of a system error in the application. The website administrators have been notified and will look into the problem as soon as possible. We apologise for the inconvenience and kindly ask you to try again or try back again in a little while.
Please click here to go back to the main page and continue working with our system.
The error received was:
Unknown Error
What should I do?
thanks,
Ganbold
the easiest way to see what the error is is to open lib/errors.inc and comment out the two lines:
set_default_error_handler(....
set default_exception_handler(....
then you'll see what the problem is.
I am trying to figure out why the text on the index.php page does not appear. Could it be caused by something not configured correctly in the PHP and MySQL files on the server. I am using PHP5.2.0.0 Apache 2.0 MySql 5.0
If I remove this line $appts = $am->getPendingappointments($g_userID, 5); then I can get the text to show up on the index.php page.
I've found that PHP is a little quirky i how it reports errors for a lot of things. In particular, those that occur as it loads in scripts -- syntax and parsing errors.
Good things to look for:
- check your error settings in php.ini and make sure that it's reporting all errors (I usually set the errors to E_ALL | E_STRICT).
- also set the php.ini file to log errors to a log file. Sometimes, when you can't figure out what's going wrong, the error file will tell you what happened.
- once you've made sure that the set_error_handler and set_exception_handler are commented out, you should have a better time of seeing what's going wrong.
I'm planning on writing a blog article about this, as PHP appears to have two "modes" of error reporting, and getting the full details of all of them can be a bit tricky sometimes ....
Then I select any of the options and it goes to showprods.php but the only thing that is on the page is the top banner and this "" in the upper left hand corner of the page. I can view the cart as well as help but won't browse product and I can't see any images.
Please provide any information you can to allow me to move forward with this script.
Regards,
Scott D.
Hey Scott!!
Those weird characters () I *think* are the UTF-8 headers. It sounds like the files on your machine have the UTF-8 headers, and the PHP interpreter doesn't like them.
If you're on Windows, you might try loading and resaving (as UTF-8) the files using Notepad.exe, or if you're on a Mac, then you should try using TextEdit.app/, and also use UTF-8. On Linux I'd use Emacs, but there might be something easier.
Thanks for all you help.
Scott
$pattern = "[[:alnum:] _-]\{$min,$max}";
return ereg($pattern, $in_uname);
I modified the function below and it seems to work:
public static function validUserName($in_uname)
{
$in_uname = trim($in_uname);
$min = UserManager::LEN_UNAME_MIN;
$max = UserManager::LEN_UNAME_MAX;
$un_length=strlen($in_uname);
if ($un_length<$min || $un_length>$max)
return FALSE;
$pattern = "^([a-zA-Z0-9_-]+)$";
return ereg($pattern, $in_uname);
}
Yah, a guy from England pointed this out a while back, and I ended up writing an article about it.
http://chipmunkninja.com/article/phptrix2
I don't know why this worked in the versions I was using when I wrote the book, but not now .... freaky!
i've been having truble with the example of user authentication chapter. Infact i usually receive this following error:
Fatal error:
Cannot redeclare class InvalidArgumentException in SiteDirectory\errors.inc on line 9
How to solve this problem??
Thanks!!
1st: great book ! Getting interested in OOP now.
I found a problem in error.php /errors.inc. Errors.inc does a
if ($PHP_MAJOR == 5 and $PHP_MINOR < 1)
{
etc.
but $PHP_MAJOR is declared in corincs.inc, which is (rightly so) NOT included in error.php.
The solution is do declare $PHP_MAJOR in error.php as well.
cheers,
Rudolph
I installed your simple blog example of your book. It seems to work well, but when I try to submit some data containing the three characters ( ‘ % ; ) which are prefixed with a backslash by your mega_escape_string function, there are two problems.
One is if I insert the apostrophe ( ‘ ): when I try to submit the text I see a totally blank page. Even if I go to see, from the browser, the html source, there is no code, zero characters. Furthermore, no data is added to the database.
The second problem occurs if I insert the percentage symbol or the semicolon ( % ; ): now the data is submitted correctly, but when it is showed in the pages, the two characters appears prefixed with the backslash!
This means that in this case mega_escape_string worked well, but what I can do to show the content without the backslashes?
Thanks.
This isn't the first book on php and mysql apps I have read, it is though much more comprehensive than any other work I have seen. Great Job.
I am only a PHP hobbyist, but I have read a good amount of literature on the subject of web apps. I highly recommend this book for its clear and concise-yet-complete treatment of the subject.
Actually came here to find the source of an error on the accompanying disk... Thanks!
Fatal error: Uncaught exception 'SessionCompromisedException' with message 'We're sorry, but there is a good chance that your connection to this site has been compromised. Please ensure that you have applied the latest security fixes to your web browser, clear your browser cache entirely, and try again.' in .../inc/simpleblog/session.inc:87 Stack trace: #0 .../inc/simpleblog/coreincs.inc(25): require_once() #1 .../public_html/simpleblog/index.php(21): require_once('/home/utree/pub...') #2 {main} thrown in .../inc/simpleblog/session.inc on line 87
Commenting out the last session data test in session.inc (~lines 78-88) allows me to see the page. HTH.
thanks for a very clear and well written book for the interested newbie like myself.
I have just spent considerable time trying to get the Appointment manager source code up and running.
Finally I have figured out that the error:
Fatal error: Call to undefined method DateTime::topOfWeek()
Is due to the fact that PHP 5.2 now defines a DateTime object before you do in your script.
This seems to be more or less the same situation you mention above concerning with the "InvalidArgumentException" class.
Whether the best way to get around this is to simply rename your DateTime class everywhere, or if all you do in the script can also be achieved using the DateTime object provided by PHP 5.2, I am not fit to figure out at this time...
Thanks and have a nice day!
P.
I am italian, sorry for my english.
First of all thank you for your book, when I will be famous with my internet application I won't forget you ;)
My problem is in the ecommerce example. I solved the problem: Fatal error: Cannot redeclare class InvalidArgumentException in D:\WebApplications\www\posterstore\errors.inc on line 148 (I have called the class MyInvalidArgumentException).
I can see the index.php but I can't surf in the site when I try to see the page showprods.php I don't see nothing (except the top banner).
showcart.php and checkout.php are ok.
Which could be the problem?
Please answer me with a simple english.
Best regards.
this is an excellent book. great work.
I have a question about using the User-Agent for session security (p. 407).
I used this on my site, however I found that when people upgrade their
browser version even if minor (for example, Firefox 2.0.0.12 to 2.0.0.13),
the User-Agent changes and as a result, they may get the alarming error
about a compromised session.
Even if this happens once in a while, this is a serious problem as
people will think the site does not function properly.
Chris
right solution (prompting for password) in pseudo-code.
My problem came from using code from the CD (simpleblog/libs/session.inc)
which throws the exception instead of prompting for password.
Thanks!
marc.
I am following your recommendations for accessing files (chapter 519).
For example if I open a file for writing (as shown on p.521):
$file = @fopen('fname', 'w');
if ($file === NULL)
throw ...
I found that @fopen does not return NULL on error, rather it returns
false and the test for the error does not work for me. Maybe my PHP
version or settings ?
I replaced the '===' by '==' and things work.
Doing '=== false' is ok too. Any comments ?
Thanks, this is a great book, it always remains at hand on my desk.
Chris
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept
cookies.
Can someone help me on this one?
Thanks
Nathan
you can select * FROM mysql.user to see who has permissions from which host, and you should double check that your app uses the right name / password combo.
I try to install the simpleblog application and I get this error (the error_handlers have been commented)
Fatal error: Uncaught exception 'DatabaseErrorException' with message 'We\'re sorry, but an internal database error has occurred. Our system administrators have been notified and we kindly request that you try again in a little while. Thank you for your patience. (Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2))' in /home/.warfield/geantbrun/lib/php/simpleblog/dbmanager.inc:49 Stack trace: #0 /home/.warfield/geantbrun/lib/php/simpleblog/usermanager.inc(470): DBManager::getConnection() #1 /home/.warfield/geantbrun/lib/php/simpleblog/loginproc.inc(21): UserManager->isUserLoggedIn() #2 /home/.warfield/geantbrun/lib/php/simpleblog/coreincs.inc(33): require_once('/home/.warfield...') #3 /home/.warfield/geantbrun/geantbrun.com/webapps/simpleblog/webapp/index.php(21): require_once('/home/.warfield...') #4 {main} thrown in /home/.warfield/geantbrun/lib/php/simpleblog/dbmanager.inc on line 49
Any hint would be greatly appreciated!
Patrick
Thank you
Patrick
Good read, as somebody who is self taught i wanted to buy a book that had a good explanation of classes and some practical applications for learning.
I was also attracted to the veteran style tips from the experienced PHP web developer.
Good read, When i was having a quick look at the source code i came into the error "MyInvalidArgumentException" class error, and your explaination of the error and update of code was appreciated. These things happen.
PS. Your naming conventions are too good for your own good!!
Warm Regards
Jeremy
I'm having problems with implementing this, I have checked the code 100x and it just wont work. The error I get when using the code exactly as in the book and using php4 is [Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in htmlgenerator.inc on line 5]. Using php 5 I get this error [Parse error: syntax error, unexpected $end in /home/nep/public_html/testsite/lib/htmlgenerator.inc on line 100] I have checked many time to make sure all '{}' are included as needed but no matter how I change it by removing one or adding one I constantly get this error. Please help.
My hosting provider restarts Apache/mySQL services every day and
I have no control over that. I have seen problems in the 'read' and
'write' functions when the DataBaseSessionStorage $s_conn variable
is stale because of the restart.
Would this issue be resolved if I obtain connections through the
getConnection() function of dbmanager.inc (p.664) ?
You should never, ever use the $s_conn variable directly, but instead always use the getConnection() method. This should avoid problems like this.
good luck!



Thanks for the book! Out of the 5 books I've purchased in a recent binge to muck with AJAX type sites yours is the one I pick up most frequently.
peace,
core