WURFL exercise

  1. Add the following new browsers to the Firefox User Agent Switcher:
    Description: Nokia 20
    User agent: Nokia 20
    App name: Nokia
    App version: 20
    
    Description: Nokia N95
    User agent: NokiaN95
    App name: Nokia
    App version: N95
    
    Description: Nokia 7110
    User agent: Nokia7110
    App name: Nokia 
    App version: 7110
    
    Of these: the Nokia N95 is a modern "smartphone" with a full XHTML browser; the Nokia 20 supports XHTML MP but does not support JPEG images; and the Nokia 7110 supports WML but not XHTML.
  2. Using WURFL, write a PHP script which delivers the WML pages you wrote last week if the browser supports WML (but not XHTML), and an XHTML page containing the same information if your browser supports XHTML. You can test this using the 'preferred_markup' capability:
    if ($WURFL->getCapability('preferred_markup')=='wml_1_1' ||
       $WURFL->getCapability('preferred_markup')=='wml_1_2' ||
       $WURFL->getCapability('preferred_markup')=='wml_1_3')
    {
        write out WML page
    }
    else
    {
        write out XHTML page
    }
    
    Note the || means or.
  3. Test this out. The Nokia 7110 should give WML, while the others will give XHTML. Note that if the user agent is the Nokia 7110, you'll need to test it using the WML browser plugin, as the Nokia 7110 only supports WML. You should upload the PHP to your home folder on Edward as I have installed the WURFL files to everyone's home folder.
  4. Use WURFL to develop a PHP script which writes out the page below. Only actually show the pictures if the browser supports them. They are JPEG format so you need to query the 'jpg' capability.
    <html>
    <body>
    <h1>Snow pictures Sat 7 Feb 2009</h1>
    <p>It does snow in southern England, apparently! Slightly less 
    often than it does
    in Florida, but hey, you can't have everything..... Snow fell through most
    of southern England on the 2nd, and remained most of the following week.
    These pictures were taken in Surrey, just west of Guildford, on the afternoon
    of the 7th.</p>
    <p><img src="http://edward/~whitelegg_n/snowpic1.jpg" 
    alt="Snow picture 7/2/09" />
    </p>
    <p>Another one later the same day....</p>
    <p><img src="http://edward/~whitelegg_n/snowpic2.jpg" 
    alt="Snow picture 7/2/09" />
    </p>
    </body>
    </html>
    
  5. Test this with the Nokia N95 and the Nokia 20 user agents. The Nokia 20 will not support JPEG images.
  6. Use WURFL to write out a web page which contains: To do this, you will need to write out different HTML for AJAX and non AJAX browsers, but you will also need to include the JavaScript from Week 3 only in a browser which supports AJAX. You can do this as follows. The capability you need to test for is ajax_xhr_type. This will either be 'standard' (on a non Microsoft AJAX browser), 'msxml2' (on a Microsoft AJAX browser), or 'none' (if the browser doesn't support AJAX).
    // support either standard or Microsoft AJAX
    if ($WURFL->getDeviceCapability('ajax_xhr_type')=="standard" ||
        $WURFL->getDeviceCapability('ajax_xhr_type')=="msxml2")
    {
        ?>
        <script type='text/javascript'>
        .... JavaScript AJAX code goes here ....
        </script>
        <?php
    }
    
  7. Test this with the Nokia N95 and the Nokia E50 user agents. The Nokia E50 will not support AJAX.
  8. Advanced: Try combining all three tests into one page