Web Design Small Cover

Buy the PDF of
Web Design:
A Complete Introduction

See the book at amazon.co.uk or amazon.com

Related Site

Web Security Topics

Related Books

Secure Communication Cover

Securing A Server Cover

Examples for Chapter 8

The Online Glossary Example

Apart from the navbars and styles and some minor layout differences, the live version of the glossary is identical to the second version of the application described in the book, so we will not present another working version here.

If you want to install the glossary scripts to run your own version of the application, you will need several things:

Access to a server with PHP

The scripts work with PHP4, and should be OK with PHP5, but will not work with earlier versions. Most servers will already have PHP support enabled. If you are setting up your own server from scratch, you can obtain PHP from the official Downloads page.


The scripts use PHP's MySQL functions, not the higher-level database abstraction dbx functions, so they cannot easily be adapted to any other DBMS. You therefore need access to a MySQL server to run the application. You will need to contact the person who administers your Web server to find out whether you can use MySQL. If you can, you will probably need a separate username and password for the database. There will very probably be limitations on what you can do. In particular, you may not be permitted to create new databases. This should not be necessary for installing the glossary data, as long as at least one database has been created for you to use.

For more information, or to download the system if you need to install it yourself, visit the MySQL Web site. You will almost certainly want the 'Community Server' version.

Some Data

With access to a MySQL database, you can create the tables required by the application and add some data to them. If you want to use the same sample data as in the book, you can download the schema and data. (SQL file, 56kB). The file consists of a set of SQL statements which will create all the tables and populate them with data, except for the histories table, which is left empty, waiting for your visitors. You can load the data into your database using the import function of phpMyAdmin. It should also be compatible with any other MySQL client. Note that you must have created a database before importing the data.

The glossary table will be filled with the terms and definitions from the glossary for Digital Multimedia. If you just want to create the tables and add your own data, delete all the insert statements, leaving the create table statements only. Note that owing to a bug, discovered after the book was published, if you do not put any data at all in the counts table, you will get some error messages the first time you test the second or third version, so we suggest that you ensure that there is always at least one row in that table, unless you want to fix the bug, by changing the last line of the function do_cloud to

return $n == 0? "": make_cloud($counts);

The PHP Code

Download the source for the glossary examples. Zip archive, 12kB.

The archive contains three sets of files, one for each of the versions of the application described in the book. They use a hopefully obvious naming convention: glossaryn.php requires the functions from actionsn.inc, for n = 1, 2,3.

Important. The archive also includes a file called config.inc, which defines the details for accessing the database. You must edit this file to insert the correct details for your installation. The places where you have to make changes are marked with Xs and a description of the required values. We have had some difficulties accessing a database server identified by its host name, and we have seen reports of similar problems elsewhere. If you find that connections are being refused by the MySQL server, try replacing its name with its IP address.

If you upload the unzipped files to your server, provided you have correctly created the database tables and edited config.inc, you should be able to use the glossary. If you use glossary2.php, you should see the term cloud changing as you make queries; with glossary3.php, you should also see the Recent Searches menu recording your history.