– Common Function Library Project


Last updated December 18, 2008


Chris Brickhouse

Version: 2 | Requires: CF7 | Library: UtilityLib

Detects whether or not user is using mobile browser by using the user-agent. Requires an API key from

Return Values:
Returns a boolean.


<cfif isMobileBrowser("apikey")>
   <cflocation url="#cgi.server_name#/mobile">
<!--- do nothing --->


Name Description Required
apikey Required API key. Yes

Full UDF Source:

 Mobile browser detector.
 v2 by Raymond Camden. Fixed var scoping, and made API key a argument.
 @param apikey      Required API key. (Required)
 @return Returns a boolean. 
 @author Chris Brickhouse ( 
 @version 2, December 18, 2008 
<cffunction name="isMobileBrowser" returntype="boolean" output="false">
    <cfargument name="strAPI" type="string" required="true" hint="API Key">
    <cfset var cfhttp = "">
    set options for http post. 
    see the handsetdetection api for more options. 
    <cfset var options = "geoip, product_info, display">
    <cfset var str ="">
    sign up for an API key from, otherwise this will not work.
    <cfset var thisxmlok = "">
    <cfset var thisxml = "">
    <cfset var server = "">
    <cfset str = str & "<?xml version='1.0'?>">
    <cfset str = str & "<request>">
    <cfset str = str & "<apikey>#strAPI#</apikey>">
    <cfset str = str & "<options>#options#</options>">
    <cfset str = str & "<User-Agent>#cgi.http_user_agent#</User-Agent>">
    <cfset str = str & "</request>">
        <cfhttp method="Post" url='' resolveurl="false" timeout="10" >
            <cfhttpparam type="xml" value="#str#" >
        <cfset thisXML = xmlparse(cfhttp.FileContent)>
        <cfset thisXMLOK = thisxml.reply.message.xmlText>
        <cfcatch type="any">
            <cfreturn false>
    <!--- throw if bad api, don't hide it... --->
    <cfif findNoCase("Invalid API", thisxmlok)>
        <cfthrow message="#thisxmlok#">
    <cfif not comparenocase(thisxmlok,"OK")>
            <cfset thisXMLOK = len(thisxml.reply.product_info.is_wireless_device.xmlText)>
            <cfif thisXMLOK>
                <cfreturn true>
                <cfreturn false>
            <cfcatch type="any">
                <cfreturn false>
        <cfreturn false>


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson