PHP
  Home arrow PHP arrow Page 2 - WAP-Enabling a Website with PHP3
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

WAP-Enabling a Website with PHP3
By: Mike Banahan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 22
    2000-06-12


    Table of Contents:
  • WAP-Enabling a Website with PHP3
  • How it Works
  • Switching to WML
  • Conclusions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    WAP-Enabling a Website with PHP3 - How it Works
    ( Page 2 of 4 )

    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:


    <? $logfilename="/www/web.places/logs/dblog"; header("Set-cookie: name=3880d6350463; expires=Saturday, 23-Mar-2002 06:08:30 GMT; path=/"); $Mytemplate["formmethod"]="get"; $Mytemplate["sessionkey"]="3880d6350463"; $Mytemplate["retrieved_cookie_session"]="Fri Apr 21 20:11:05 2000 "; $Mytemplate["lasttimeon"]="956344265"; $Mytemplate["placetype"]="1"; $Mytemplate["QUERY"]="a=show_link&unique_id=175&placetype=1"; $Mytemplate["mapimagewidth"]="292"; $Mytemplate["mapimageheight"]="219"; $Mytemplate["east"]="414996"; $Mytemplate["north"]="435499"; $Mytemplate["placename"]="Park"; $Mytemplate["title"]="Place Details, Park"; $Mytemplate["OSGB"]="SE 149 354"; $Mytemplate["latlong"]="053 48\" 55'N 001 46\" 19'W";
    ... and a lot more like it.

    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:


    <? require('stdhead.tpl'); require('stdplace.tpl'); $thisplace = new PlaceDetail(); if (isset($place)) { $thisplace->import($place[0]); } $thistypes = new TypeList(); if (isset($type)) { $thistypes->import($type); } $REenter = "sessionkey=" . R("sessionkey") . "&rlimit=" . R("rlimit") . "&east=" . R("east") . "&north=" . R("north") . "&unique_id=" . $thisplace->unique_id . "&placetype=" . R("placetype"); if(I("o-east")){ $REenter .= "&o-east=" . R("o-east") . "&o-north=" . R("o-north"); } $basicformfields = "<input type=hidden name=a value=\"show\">\n"; $basicformfields .= "<input type=hidden name=placetype value=\"" . R("placetype") . "\">\n"; $basicformfields .= "<input type=hidden name=sessionkey value=\"$K\">\n"; $basicformfields .= "<input type=hidden name=rlimit value=\"" . $Mytemplate["rlimit"]. "\">\n"; if (I("o-east")){ $basicformfields .= "<input type=hidden name=o-east value=\"" . $Mytemplate["o-east"]. "\">\n"; $basicformfields .= "<input type=hidden name=o-north value=\"" . $Mytemplate["o-north"] . "\">\n"; } $basicformfields .= "<input type=hidden name=east value=\"" . $Mytemplate["east"]. "\">\n"; $basicformfields .= "<input type=hidden name=north value=\"" . $Mytemplate["north"]. "\">\n"; $basicformfields .= "<input type=hidden name=\"unique_id\" value=\"" .s $thisplace->unique_id . "\">\n"; $votepics = array("twocross.gif", "onecross.gif", "onetick.gif", "twotick.gif", "threetick.gif"); $votealts = array(":<", ":(", ":|", ":)", ":>"); // and a lot more besides ...
    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.

    This article copyright GBdirect Ltd 2000. All rights reserved. Reprinted from http://www.gbdirect.co.uk/ with permission.



     
     
    >>> More PHP Articles          >>> More By Mike Banahan
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek