Ever wonder what it took to get a site to work on those new "web-enabled" cell phones? This short tutorial will do just that by giving you the basics of making your site WAP-enabled using PHP.Reprinted from http://www.gbdirect.co.uk/ with permission.
The CGI program runs on response to every incoming query and is easily fast enough to fill our data pipe without having to resort to trickery like Apache modules or fastCGI. Each execution of the CGI inspects the incoming form and uses that to decide which presentation template should be used. These presentation templates (nothing to do with the C++ `template' construct) are php3 pages. The CGI program's output is essentially a long list of php3 data definitions; here's a fragment:
After spitting out the data, the CGI program opens the php3 template file and tacks it onto the end of the data definitions, so it's acting much like the `cat' command. The whole pasted-together chunk is sent through a pipe into the php3 interpreter and the output of that is also piped asynchronously through `weblint'; if weblint picks up any errors, it emails us to warn that we are generating bad HTML. All this is done for every page generated. Running on an AMD K6/250 it looks as if we can do about one page per second, including the map generation before we would have to turn off the weblinting or look for more power.
Here is a fragment from the `place' php3 template, this is the one that executes if you click on the link to The Park pub:
It's probably obscure unless you know php3 but I thought I'd
include it for those who know it. A lot of the calls like R(), I() and so on are functions defined in stdhead.tpl - they extract data from the predefined arrays but also report errors if expected data is missing, helping us to debug the interface between the CGI and the php.
That all works - the CGI->php3->weblint->user chain is highly effective. By having the logic in the C++ and the HTML generation in the php3 two people or teams can work simultaneously on the project without getting in each other's way much and what's more, if you are tinkering with layout you know you can't break the data engine or corrupt the database easily. This is typically not the case with `traditional' php3 work where data management and layout get badly intermingled. At least they do when I'm writing the stuff, maybe there are some star performers who can manage to do better; I take my hat off to them if they exist.