SolutionsTools & SDKSupportForums Register



Quick Links
 
How to Differentiate the Client Device
 
 
Several classes of Web clients could potentially access your site, both traditional web browsers and WAP browsers, so it is important to determine the content that should be delivered to each client. The WAP WML specification can be varied in its interpretation and devices containing browsers from different manufacturers may render some elements differently. To write a great application you should therefore determine the type of browser (Nokia or Openwave) in the code. Then develop customised versions of your application and branch to the relevant code set depending on the type of browser accessing your app. This will allow you to enhance usability for the Openwave browser while ensuring usability on the Nokia browser is not impaired.

The following sets of code address three possible situations:
  • A client that expects HTML
  • A Nokia browser
  • A device with the Mobile Browser v3.1 or 4.x that supports WML 1.1
To identify which client is accessing your site, investigate two different HTTP headers, HTTP_ACCEPT and HTTP_USER_AGENT. While neither of these is part of the WAP specifications, they are both standard HTTP headers defined in rfc1945. The first step is to look the HTTP_ACCEPT header and parse it for the inclusion of text/vnd.wap.wml:

Perl

#!/usr/local/bin/perl
$acc = $ENV{"HTTP_ACCEPT"};
$ua = $ENV{"HTTP_USER_AGENT"};
if ($acc =~ "wml"){
  deliver wml
} else{
  print' Location: http://mysite.com/index.html'."\n\n";
}

Java

public void doGet (HttpServletRequest req, 
    HttpServletResponse res) 
    throws ServletException, IOException{

String acc = req.getHeader("Accept");
String ua = req.getHeader("User-Agent");
ServletOutputStream out = res.getOutputStream();
if (acc.indexOf("wml") != -1){
deliver wml
}
else {
res.setHeader(res.SC_MOVED_TEMPORARILY);
res.setHeader("Location", "http://mysite.com/index.html");
}

ASP

<%response.buffer="true"
Dim accstring
Dim uastring
uastring = request.ServerVariables("HTTP_USER-AGENT")
accstring = request.ServerVariables("HTTP_ACCEPT")
If (InStr(accstring,"wml")) Then
Deliver wml
Else
Response.Redirect("/index.html")


HTTP_ACCEPT header



In all of these cases, it has been established that the client sends WML in the HTTP_ACCEPT header and can thus assume that WML should be delivered. If WML is not found in the ACCEPT list, HTML is delivered. This ensures that HTML is delivered to web browsers and to spiders (crawlers, site indexers).
Once a WML device is found, it is possible to discriminate further to see exactly which device is accessing the site.

The following device possibilities are accounted for in this code: (1) the Mobile Browser from Openwave, (2) A Nokia browser.

Perl

if($ua =~"UP.B" || $ua =~"UP/"){
    print "Location: /opwv/index.wml \n\n";
}
    else{
        print "Location: /nokia/index.wml \n\n";
    };

Java

if ((ua.indexOf("UP.B") != -1)) || (ua.indexOf("UP/") != -1)){
    res.setHeader(res.SC_MOVED_TEMPORARILY);
    res.setHeader("Location", "/opwv/index.wml");
}
else{
    res.setHeader(res.SC_MOVED_TEMPORARILY);
    res.setHeader("Location", "/nokia/index.wml");

ASP

If((InStr(uastring, "UP.B")) || (InStr(uastring, "UP/")))
    Response.Redirect("/opwv/index.wml")
Else
    Response.Redirect("/nokia/index.wml")

The above code is known to work, however this may not be the most efficient way to achieve the desired end result. The configuration files of some web servers (Apache for instance) can be modified to deliver WML or HTML to a device as appropriate. For optimal results regarding redirection, you should consult the configuration documentation for the web server which you are administering.
 
Copyright © 2000-2008 Openwave Systems Inc.    About Us  |  Openwave  |  Terms & Conditions  |  Privacy Policy  |  Update Profile