UQ Students should read the Disclaimer & Warning
Note: This page dates from 2005, and is kept for historical purposes.
How this site works
Apache's URL rewriting engine, mod_rewrite, is used to send all URL's to an index.php file. This is the mod_rewrite used on this site.
The URL's are parsed by the PHP file, and split around any periods in the URL and stored in an array.
Care must always be taken to ensure that anything able to be externally passed into a file isn’t malicious. This function attempts to find PHP and HTML files, and returns a default PHP file if none are found. This can prevent anyone attempting to access anything unusual.
Files are stored as XHTML or XML. XHTML files are parsed for their body, style and title tags and these tags are then included into the resulting output. This allows a simple template system where the content can be created with any XHTML capable editor. I have found this to be the simplest way of creating a consistent and easily updateable style across a site.
There are several advantages and limitations to this approach.
- Slightly more processing is required to parse a file, rather than serving straight HTML
- Initial design is more complex
- Easily updateable
- Easy to maintain
- Consistent across an entire site
- Content generation possible with the majority of “webpage” HTML editors, as well as by hand
- Foreign content assumes a consistent style after parsing
- Possible to create complex file hierarchies without the user being aware
- Allows the logical file system to change without affecting existing URL’s
- Does not limit URL’s to HTML, PHP or any fixed extension. In fact, using this-site, this-site.html, this-site.php and even this-site.no-known-file.extension as links will not affect the page that is displayed.
- Allows an easy upgrade from existing non-template sites, as existing “legacy” URL’s will continue to work alongside the newer URL’s, and not all existing pages need be updated at the same time as various sections can simply be parsed out of those pages and into the new template.
This site uses an XSL based comments system.
PHP is used to run an XSL processor, as below. The comment, author and various other information is passed to this processor, which in turn applies a style sheet to it, producing an XML output file.
This is a slightly simplified version of the XSLT style sheet used to save comments.
A very similar process is used to display comments. PHP is once again used to run an XSLT processor, and the page information passed to that processor. Once again, an XSLT style sheet is applied to this information, using the previously stored XML comments file, and the output displayed in the browser.
This is a simplified version of the XSLT style sheet used to display comments.
Update from the year 2011… Sadly, XSLT is annoying and not especially useful for anything particularly complex. I no longer use it, and have had to remove the below links.
Amused Site Code
Several examples of the working code used to generate my amused site are available.
- PHP template and comment supporting code
- XSLT to save a new comment
- XSLT to show a single per-page comment as at the bottom of here
- XSLT to display and sort all comments as shown here
- XML comments file that stores the comments
- Comments file schema
- Temporary XML comments file
Please remember that this code is © Copyright