Chapter 6: A Content Management System
Overview
So far, we've seen several examples of database-driven Web pages: pages
that display information that's culled from a MySQL database when the page
is requested. Until now, however, we haven't seen a solution that would be
much more manageable than raw HTML files if it was scaled up to encompass
a Website as large and complex as, say, sitepoint.com. Sure, our Internet
Joke Database was nice, but when it came to managing categories and authors,
we'd always have to return to the MySQL command line and try to remember complicated SELECT and INSERT statements,
as well as table and column names, to accomplish the most menial of tasks.To make the leap from a Web page that displays information stored in
a database to a completely database-driven Website, we need to add a content
management system. Such a system usually takes the form of a series of Web pages,
access to which is restricted to users who are authorized to make changes
to the Website. These pages provide a database administration interface, which
allows a user to view and change the information that's stored in the database
without bothering with the mundane details of SQL syntax.The beginnings of a content management system were seen at the end of "Publishing MySQL Data on the Web", where we allowed site visitors to add
jokes to, and (if you worked through the challenge) delete jokes from, the
database using a Web-based form and a "delete this joke" link, respectively.
While impressive, these are not features that you'd normally include in the
interface presented to casual site visitors. For example, you don't want someone
to be able to add offensive material to your Website without your knowledge.
And you definitely don't want just anyone to be able
to delete jokes from your site.By relegating those "dangerous" features to the restricted-access site
administration pages, you avoid the risk of exposing your data to the average
user, and you maintain the power to manage the contents of your database without
having to memorize SQL queries. In this chapter, we'll expand on the capabilities
of our joke management system to take advantage of the enhancements we made
to our database in "Relational Database Design". Specifically,
we'll allow a site administrator to manage authors and categories, and assign
these to appropriate jokes.As we've seen, these administration pages must be protected by an appropriate
access restriction scheme. One way to do this would be to place the relevant
PHP files into a directory that was protected by an Apache-style .htaccess file that listed authorized users. Consult your
Web server's documentation or ask your Web host for information on how to
restrict access to Web pages.Since we'll work with some fairly large PHP files in this part, it'll
be necessary to gloss over some of the details, because of space constraints.
The complete code of all the files discussed in this chapter, together with
the SQL code you'll need to create the database tables from scratch, will
form a complete content management system, and is provided in the code archive
for this book.