PHP MySQL Website Programming
In brief: This book takes you through designing a PHP website, featuring the usual bundle of generic features, simple content management, adverts, forums and an on-line shop. It's not intended as a definitive codebase of the absolute best design, but fills a big gap between trying to develop PHP with functions and lots of include files, and the full Computer Science bible of Design patterns.
For those people (and there's a lot of them) who have grown from Word macros and Visual Basic, then had a lot of fun learning PHP, this book provides an excellent gentle path towards using classes in PHP and applying them to real world problems. Like a lot of Wrox books, it's jam-packed with code, with a good flow of new information in each chapter.
What I likedAs a programmer who many years ago swore blind that there was no reason for using classes and objects on websites (the equivalent to a misspent youth), this book gives good clear examples on how they can provide advantages over just 'include' and a few functions.
The book is enjoyable to read; it focuses on the step-by-step delivery of a very dynamic website,starting with the basics of designing the file layout and how the files will work together. It then goes into more detail on delivering each feature, provides enough general ideas to help most PHP enthusiasts and budding developers understand the basics and advantages of OOP programming (although there are a few functions thrown in to ease in those not conversant with OOP).
The website that you learn to create (using the Problem - Design - Solution approach) is available for you to see online here.
Although a lot of the code is focused around implementing a reasonably simple set of Patterns, Data Objects and Page execution scripts, there are a few gems in there.
- Utilizing quite a few PEAR classes including the Database abstraction layer, Mail Sending.
- A nice section on the basics of RSS and XML, not to detailed level, but a good warmup for anyone coming from a System Admin or Simple Visual Basic level.
Ok, It's not for everyone. If you've done any Java or C++, this book is going to be a bit below you. Design Patterns are not mentioned directly in the book, although a number are implemented. The book misses out on quite a few important ideas, like templating php sessions in the body, although it does touch on the subject near the end. Given the target audience, of PHP of beginner to intermediate level, it does have a few unusual code styles in places, which hopefully the readers will not over-apply.
What you will learn from this book
- Elements required to build a useful 3-tier web application
- Design and construct an interactive User Interface (UI)
- Provide a CMS environment to manage content securely and extensively
- Create visitor accounts, to register and manage unique site visitors
- Build a simple news management and delivery system
- Create a syndication application
- Generate a sustainable revenue stream from advertising
- Implement an online visitor poll
- Create a fully featured discussion forum
- Build an online shopping cart system with checkout features
You can purchase PHP MySQL Website Programming from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Seriously, a college education in MIS provided everything you need to create a fully scalable, multifacted, fully functional e-commerce portal to create new paradigms of customer interaction.
Although I use Java, where OOP is hard to avoid (and I wouldn't want to most of the time), I don't see the need to introduce the performance sapping abstraction of setting up classes and so forth with web scripts.
Let's face it, by the time you've declared you classes, instanced everything a procedural approach would probably have executed and be wating for the next client...
Code, Hardware, stuff like that.
Build a simple news management and delivery system
Generate a sustainable revenue stream from advertising
Implement an online visitor poll
Create a fully featured discussion forum
?????
Profit!!
Information wants to be beer.
The problem is that with security, the very best possible way to keep your site secure is to a) purify incoming data and b) keep your source to yourself unless you want people to let you know where the bugs/holes are. I know the open source community is really good and has it's place, but when it comes right down to it, if you fully customize your PHP, then it's more secure because there aren't a bunch of script kiddies looking for ways to hack you on security forums (a la PHPBB script attacks). The good thing about PHP in the open source sense is that you can read it and understand how it works. I don't recommend using any custom packages because there is risk involved that your doing so is going to attract attention from script kiddies. The best thing you could do is learn PHP by the open source examples (run phpbb and read it, run smarty and read it - understand it) but then create your own base, and add your own layers to it.
"For those people (and there's a lot of them) who have grown from Word macros and Visual Basic, then had a lot of fun learning PHP"
What do you mean, "fun learning PHP?" I'm a Microsoft guy and there's only one way for me... the Microsoft way. Buddy, I think you should be talking about ASP and VBScript, the nectar of the gods.
I started my career hacking up Word macros, then slowly picked up Visual Basic. I can't wait to see what Microsoft has in store for me next. Maybe Visual C#? Hmmm... I won't touch anything non-Microsoft with a ten foot pole, because Microsoft always comes out with the best cool shit and I'm a big fan.
I don't know why you people can't just accept Microsoft and all its products and move on with life.
At this point, you cringe in fear of two problems, the spaghetti mess that you are about to deploy, the ongoing maintenance nightmare and the horrors of modifying it to fit your needs.
There are three types of people in the world: those who can count, and those who can't.
As a programmer who many years ago swore blind that there was no reason for using classes and objects on website
I put together a javascript/php-based web aministration tool for a web site, that without classes, would have been a nightmare. Classes aren't necessary in every case, but when the problem space reaches a certain level of complexity, NOT using them can be a very poor choice. But then, after one decides that classes would be appropriate, using them effectively is a whole different ball game.
in 24 hours
There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
My biggest gripe about PHP in regards to classes is that you CANNOT create a deconstructor function in your classes. Their reasoning is that they cannot make it where you know which order the deconstructors will be called.
Instead, the workaround is to create a function to handle the script ending using register_shutdown_function(). This is incredibly annoying, and for the most part I don't even use it. It just forces me to write a function called ClosePage or something to that effect.
I like classes, and it's worth at least looking into using them on your pages (at least for code you'll be constantly reusing). For those of you who are concerned about speed in using classes, get PHPA.
Hopefully PHP5 will fix some of the issues in using classes in this language. But until then, be hesitant.
/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
The example code is contrived and ignores a lot of real world problems. Of course, if you're writing a shopping cart of your own, you won't learn anything new here. If you don't know php and want to add some dynamic content to your web pages, it's a good book, though.
Do you even lift?
These aren't the 'roids you're looking for.
To those familiar with it, #5 obviously is:
In Soviet Russia, Jesus asks: "What Would You Do?"
Part of the reason it applies so readily to this language, however, is the conceived ease-of-use. A lot of newbie users swap to PHP, pick up some bad samples, combine with existing bad habits they never grow out of, and eventually consider themselves "knowledgable" just to to long-term use. However, experience in duration != experience in education (standardization, etc).
To shift the blame from PHP, I've been working on attempting to integrate a 3rd-party web-based system (Perl-base) into my place of work. At first, I looked at the code and estimated that I could do it relatively easily. What I neglected to realize, is that while some of the coding was done reasonably well... this seems to be a multi-person project and other sections are nightmarishly and un-necessarily complex.
We need an article on "signs that you're working with bad code." So far I've found...
- Poor indentation
- Low commentation (for godsakes, use # and throw in at least a few words every now and then
- Really ambiguous variable names: $x1, $x2, $blah, $stuff
- Odd information passing: As a delimited string...which is interpreted differently based on certain conditions (contents of string may vary)
Maybe we need a "warning signs" section. Anyone got one?There are several promising PHP frameworks in development.
Ports of Struts
PHP.MVC
Phrame
And ezPublish 3 which is primarily a CMS but can also be used as a general purpose framework.
IMHO for one of these to really take off (like Struts) is what professional PHP development needs.
The astonishing thing is that it continues to work!
Congratulations! Now we are the Evil Empire
Checked out the shopping cart feature first, since I've coded a ton of shopping carts.
TERRIBLE!
I type in 9999999 (ad infinitum) in the quantity field and hit update.
My quantity is mysteriously changed to 147483647. I'm just guessing that's the limit of signed ints on that server. No error message was displayed. Since the size of the field that displays the quantity box is 3, all you see is '214'. An end user of an e-comm site doesn't care what's behind the scenes, they care that the inputs/outputs make sense. This doesn't. The reviewer talked about Design Patterns. Who cares? On the web the first rule you need to follow to have a reliable application is 'Validate user data'. Do that obsessively and you'll probably be ok even if your back end isn't too slick. Fail to do that and you are sunk, no matter how efficient your code is.
Then just to be sure I wasn't being too harsh, I ordered -3 of another movie. Works fine. So you can order three of one movie, -3 of another, and get them for free. Sorry.... a shopping cart without data validation (tedious as it is) isn't a shopping cart.
I hit continue and am told I need to have an account first. I sign up for one. First thing - I'm prompted for my login. Grrr... pet peeve - maintain this in the session please. Then I'm not redirected back to the cart. Oops... lost sale there. So I continue.... lovely, I'm informed that "Error_ Your shipping info is not valid." Man... insulting too. I hate apps that set a user up to fail.... and this does. I update my shipping address as prompted... and nothing happens, I don't go back to the flow of purchasing. Yikes, another lost sale. Even on the last step, my -19.99 order is accepted with no problems.
I know the shopping cart is being offered as an example only.... but c'mon, it should be a workable example. I am looking to learn PHP, but think I'll look elsewhere.