bitrazor.com ...THE source for mediocre content                                      

Information About This Site's Construction

If you're interested in some of the general design principles I followed while creating this site, read on.

This site was written in PHP, a great server-side scripting language. Even though the majority of the site is static content, I've used PHP to simplify the maintenance of the site, and to make global changes simple. My hosting company, NoMonthlyFees, also provides a MySQL database that I use for some of my utilities.

Tools

HTML-Kit Screenshot I use several tools when developing my site. Since my excellent hosting company supports Apache, PHP, and MySQL, I have installed these fine free products on my system at home, so I'm running the same environment here. Granted, the path to everything is different on my local system, but because I'm using the site-absolute technique I describe later, I can copy the entire contents of my website from one machine to the other and everything works perfectly. This is extremely useful when doing major development, like right now, so I can edit and test on my local system, even if the network is down.

For text editing, I'm using the freeware HTML-Kit (right), which is a great editor for the price. You can even edit directly on your site and it'll handle the FTP downloads/uploads behind the scenes -- very cool.

For the bulk of my FTP transfers, I've not found a better FTP program than CuteFTP, and I've looked at a bunch of them. I've even paid for a couple others, but I think I'm gonna plunk down the $40 for this one before the demo expires, because it's really, really good. [Dave's note: $40 sounds like a lot until I think about writing my own. Then $40 sounds like a pretty good deal. Dave does not do Windows.]

I must also stick a plug in for the excellent, excellent user-annotated PHP manual, found online at http://www.php.net/manual/en/. This is the coolest way to get information, and I have found so many shortcuts and avoided so many pitfalls using this thing. I wish every online manual had this capability. Real, intelligent users tell you when you're using something the wrong way, give you great code examples you can steal directly, etc. It's really great. Even if you don't know PHP, check out the manual.

Books and References

I looked at a bunch of PHP books, and this is the one I bought. It's pretty good, and it covers a lot of different areas like style and databases. Makes a decent reference too.
This book is an excellent introduction to pitfalls to avoid when doing anything computer-related.
I use this book constantly as a reference for Cascading Style Sheets (CSS) and Dynamic HTML (DHTML). It's small, you can read the whole thing in an hour and a half, and you'll learn jusst about everything you need to to make a site more interesting.

Tricks, Conventions, and Design Principles

Use Site-Absolute Links

When building a site, one must choose whether to link things relative to the current location, e.g.

<A HREF="afile.php">A File</A>

or absolute, e.g.

<A HREF="/some/dir/afile.php">A File</A>

Relative links are better when building a static site in HTML only; you can pick up the whole tree and put it anywhere you want. This is particularly useful when developing your site on one system, like your home machine, and deploying it to another, like your hosting site.

I have decided to go with a hybrid approach. Anything that requires a reference (links, as well as PHP include() and require() statements) is site-absolute. What that means is, the location of the files can change automatically from server to server, but the folder tree stays the same. Hell, that wasn't clear at all. Here's an example:

<?php include($_SERVER["DOCUMENT_ROOT"] . "/site/defaults.inc"); ?>

This means that I can't move defaults.inc around in my web folder tree without breaking a bunch of links, but at least I can copy the files from my local machine to my remote hosting site (where the paths to the root of my web site are completely different) without breaking anything. This turns out to be a great compromise, because if I ever did want to rearrange things from say /site/defaults.inc to /site/inc/defaults.inc, I could use a decent editor to do a global search and replace, no problemo. Allaire HomeSite and Cold Fusion Studio are examples of editors that allow you to do these kinds of global search and replacements on a project-wide basis.

Site-absolute references also have advantages when scripting a site. In my example, each category of content (e.g. "personal") has its own content map, which is just a page with a bunch of links. I have developed each of these content maps in a way that they may be included in multiple places (for example, in the "personal" category page, as well as the site map). In this way, I can maintain the links in one place, and have multiple pages updated automatically. You will find this is a central theme in my website's design.

One more thing to note: when creating site-absolute references for the <A> tag, you don't need the $_SERVER["DOCUMENT_ROOT"] prepended.

Handle PHP require() Statements Gracefully

In PHP, you can use either include() or require() to include other PHP scripts into the current one. require() is faster and cleaner; include() is more forgiving. Neither solves the problem of avoiding nested includes (require() only solves it for the current script, but fails to prevent problems if the includes are nested). Update: as of PHP 4, there's now a require_once() (and also an include_once()) that solves this problem and prevents multiple includes or requires.

Put Some Thought into Your Directory Structure First

This sounds obvious, but nobody ever does it -- they start adding content, then spend time later to change everything. Here's a few conventions I like:
/siteSitewide stuff, like includes and templates
/stylesStylesheets (you might also just lump into /site)
/contentStatic content goes here
/imagesDumpster for all those icon.gif images you'll collect

Create a Site Template

Craft a template file that you can use as a starting point for new files. Here's mine:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<?php include($_SERVER["DOCUMENT_ROOT"] . "/site/header.php"); ?>

<?php include($_SERVER["DOCUMENT_ROOT"] . "/site/footer.php"); ?>
</body>
</html>

Create a header.php and footer.php:

From my template above, you can see that I have a header and footer include. My header has all of the menuing stuff, as well as a reference to the stylesheet. In this way, I can change the look and feel of the site in one place.

The careful reader will notice some of the tags are unbalanced. For example, notice that the <head> tag is in the file, but no </head> or <body>. These are in the header.php include file, because we want header.php to specify some stuff that belongs in the head, such as the stylesheet, while other stuff, like the page title, belongs in the page. As long as you're consistent, this unbalanced tags impurity won't cause you any problems, and it makes some things nicer.

For Each Category, Create an intro.php and map.php

(content pending)

Use Functions to Generate Often-Used Items

like link_header() (content pending)

use CSS1 Stylesheets, and Lightly Assume IE

(content pending)

Use PHP Classes

and also use the trick of including all classes via classes.php vs. including individual classes via class_<classname>.php (content pending)



                                                         Last updated: August 7, 2009