Several months ago, I got very, very tired of maintaining a large number of separate, standalone pages on my site. Since my pages were exactly the same except for three things (meta description tag, title tag, and content), I decided to create a database table that could hold this information and a single page that could be used to display all the information.
As far as I'm concerned, PHP and mySQL are nothing but tools to further my habit of code laziness. What you have here is the result.
This package consists of five files: add_page.php, content.php, install.php, index.php, and a readme file.
Instructions:
1) Change the database information in all four files. In addition, you will also need to provide the final location of content.php as a variable in add_page.php — so that when add_page.php displays confirmation that a page was created, a link can be made to the page (so that you can view the page immediately).
2) Open install.php in a web browser. This page installs the required table and default page in mySQL. If installation succeeds, you'll see a success message (and you may delete the install file immediately). If there are issues, post here, and include the mySQL error message you encountered.
3) Set up a folder that is protected via .htaccess. There's even a tutorial on this site somewhere. Do NOT leave add_page.php and index.php in a folder that is unprotected by .htaccess. Doing that creates a major security hole, and basically you deserve what you get if you do that.
4) Upload index.php and add_page.php to the .htaccess-protected folder. You should immediately be able to start adding pages to the database.
5) Upload content.php to your site. This is the file that users will load to see your content, so it needs to be publicly available (meaning, NOT in the .htaccess-protected folder). In its current form, it is very, very bare – you will want to edit it to reflect the design of the rest of your site.
That should be all. Do not delete the page named 'default' – that is what will be displayed on your site if the URL does not have a query string or the query string is invalid.
You can see it on my site here:
http://domesticat.net/content.php – the default page, listing all currently-available pages
http://domesticat.net/content.php?q=writing – a page that provides a bit of a starting point for my site
Bonuses for this way of doing things: fewer HTML pages to maintain, plus the ability to make content changes to my site through a web interface. I find this really, really useful to me when I'm traveling (which I'll be doing a lot of in the next three months) or otherwise away from the files on my home computer.
Just, please…if you're going to do something like this, be prepared to make backups of your database on a regular basis. If you don't, you risk major, ugly problems if you have some kind of database failure. Talk to your sysadmin or a knowledgeable friend about setting up automated backups if you're not comfortable doing it yourself.
The zipfile containing the pages and these instructions may be obtained at http://domesticat.net/misc/external_pages.zip (8k zip file)
(I'd also like to note that this code is quick, dirty, and not nearly as efficient as it could be. I'm just trying to get this crossed off my to-do list prior to heading north to Washington D.C. Better than not making it available at all, I think!)