CF WML Tutorial: Browser Detection and Redirection

Folks often wonder how to detect that a visitor to their site is either a WML or HTML client. Some realize that all browsers (html and wml) report to the server they're visiting such information as their ip address and the type of browser they are. This latter information is available to CF developers as the cgi.http_user_agent variable.

But a better choice is to use the variable that reports what type of content the client will accept. If it accepts WML, then send it WML.

I use this on the front page (index.cfm) of my HTML-driven site, to send wireless visitors to a WML-driven location. <CFIF CGI.HTTP_ACCEPT CONTAINS "text/vnd.wap.wml"> <CFLOCATION URL="/wml/index.cfm"> </CFIF>

Handling Redirection: Not as Obvious as it Seems

Note that if you choose to use CFLOCATION to do the redirection, there are known issues whereby you should not use a page-relative link to another directory but instead a webroot-relative one. This is just to avoid problems on some web browsers and/or gateways.

To clarify, if the "wml" directory had been a subdirectory under the location where my index.cfm (in which this code is placed), you might think you could just use:

<CFLOCATION URL="wml/index.cfm">

That would certainly be valid in any html-driven site. But many have experienced that this fails in wml-driven pages. It's not a WML issue, but one in the gateways doing the processing between the client and the server.

Fortunately, if this index.cfm is in the root of the web server (or the root of a virtual domain) and the wml directory is below it, the use of a slash before the path will solve the problem, as was done in the first example. If your pages are deeper in the web root path, make adjustments accordingly.

WML Resources:

| Home | ColdFusion | Articles | Presentations
| User Groups | Other Resources | Press Releases | Company

© 1998-2024, Charles Arehart, SysteManage
Our Practice Makes You Perfect