Tim Anderson begins a new Hands On series with an introduction to dynamic web site development.
If you want to build dynamic web sites, this new Hands On section is for you. A dynamic web site is one where the content is not fixed, but partly generated under program control. This opens up a huge range of possibilities, such as database access, sites that are easy to navigate, online purchasing, and more.
- Web development scenarios
Before going anywhere with web development, you have to be clear about how your solution will be deployed. The two key factors are first, which technologies you use; and second, where the website is hosted.
Fig 1 shows the most common technologies, divided into those that are executed on the client and those that run on the server. Fig 2 illustrates the matrix of hosting possibilities.
Client-side technology will always be problematic on the internet because you know nothing about the client except that it's some kind of browser.
You can flag your site as for Internet Explorer 4.0 and higher only, or have browser detection with alternate sites for different browsers, but it isn't easy to get it right.
Server-side technology is easier, in that you at least know what server you're using. If the server is in a box next to your desk, you can have everything your way.
On the other hand, for those with dial-up accounts and web space hosted by an ISP, there are problems. Your web space is on a server shared by other users, so ISPs are picky about letting you run scripts or executables that increase the server load and might cause problems or crashes. Generally, the more commercial (and expensive) accounts with ISPs have fewer restrictions.
- Run your own server
Even if your website is destined for web space hosted by an ISP, running a local web server makes a lot of sense. The easy option is the Personal Web Server or Internet Information Server, bundled with Windows. IIS, in particular, is an excellent product, except that your ISP probably doesn't use it. On the internet, nearly 60 percent of websites use Apache (Fig 3), almost all running on some variety of Unix.
If that includes your ISP, it makes a lot of sense to download Apache and install it on Linux, neither of which need cost you anything more than online time and a spare PC on your network. Learning Unix is handy for web developers, in any case. The web grew up on Unix, and chances are you'll be telnetting into a Unix server and will need some basic commands.
Having said that, many ISPs do offer NT and IIS as an option, so you can stay inside the cosy Windows world if you want. On a Windows intranet, the tables are turned and IIS is the obvious choice. This column will cover both.
- Server Side Includes
Server Side Includes (SSI) are a great place to get started with dynamic content, since they are simple and widely supported.
This is in the realm of server-side technology though, so check with your ISP before assuming that anything will work. It's no use trying to run SSI tags by opening web pages as files - they must be served by a web server.
SSI works by parsing placeholders in your HTML page. Each placeholder is replaced with content generated by the server. SSI placeholders are of the form:
attribute="value" ->
and one of the most useful is the simple include command. which inserts a file into the HTML page before it is sent to the browser. For example, you might be developing a site with a navigation panel on the left.
You could use frames, but these have some drawbacks, so another approach is to have the navigation panel repeated on every page. That works well, except that if you add a page, every panel in the sequence needs to be amended.
The include command lets you keep the panel in a separate file, so that you only have one copy to maintain. For example, you might have a file called navpanel.html that looks like this:
You need to save this with an .shtml extension. The different extension tells the web server to parse the file. On IIS, you can also use .stm.
These extensions are configurable options. You could tell the web server to parse every .html file to look for includes, but this is a heavy performance hit.
Here are some other useful commands:
var="value" - >
returns the value of a web server environment variable. Useful variables include DATE_LOCAL, LAST_MODIFIED, HTTP_USER_AGENT and others. Try the following to get a list of all the variables on an Apache server:
The following gets the size of a file, handy for downloading pages:
In this and other commands which refer to files, you can either use the virtual= attribute, which uses the relative URL, or the file= attribute, which is a relative file path. To configure the format for dates, times and file sizes, use the config element.
Two interesting SSI elements for a programmer are exec and if. The first executes a command or script. If you use the exec element, use the CGI attribute to specify a CGI script and the CMD attribute for a system command.
The output from the command ends up in the HTML page.
A useful tip is that you can execute CGI scripts using a virtual include, so exec isn't often necessary.
The flow control elements are part of extended SSI (XSSI). The elements available are if, elif, else, and endif:
Show this text
Show this other text
These work in Apache 1.2 and above, but not on IIS. The condition supports regular expressions as used by the Unix egrep search command, so keep that Unix reference handy for this one.
While IIS does support SSI, you can't use much SSI in an Active Server Page because an ASP has its own parser.
PCW CONTACTS
What do you want to know about web development? Email webdev@pcw.co.uk with your questions and comments, as these will determine the future direction of the column.
- You can discover what server your ISP is using by visiting www.netcraft.com and running a query there.
- Get Apache from www.apache.org, in source or binary form.
- There's an online reference to SSI at www. apache.org/docs/mod/mod_include.html
Related articles
Q.Why are some of the keys on my keyboard doing strange...
Q.Is my phone’s Bluetooth any use?
Q.Can I switch boot drives so that I can work on older...
St Helena, a 'small British village' in the mid-Atlantic, is seeking support and funding for a broadband connection
|
|
|
|
|
Computeractive Excel (2010) Online tutorialPrice: £19.99 |
Computeractive Word (2010) Online TutorialPrice: £19.99 |
Computeractive Powerpoint (2010) Online TutorialPrice: £19.99 |
Angry BirdsPrice: £9.99 |
Back Issue CD-Rom 14 (2011)Price: £15.99 |