User Agent Library
The User Agent Library provides handlers that help identify information about the browser, mobile device, or robot visiting your site. In addition you can get referrer information as well as language and supported character-set information.
Initializing the Library
Like most other libraries in revIgniter, the User Agent Library is initialized in your controller using the rigLoaderLoadLibrary handler:
rigLoaderLoadLibrary "Useragent"
User Agent Definitions
The user agent name definitions are located in a config file located at: application/config/useragents.lc. You may add items to the various user agent arrays if needed.
Example
When the User Agent Library is initialized it will attempt to determine whether the user agent browsing your site is a web browser, a mobile device, or a robot. It will also gather the platform information if it is available.
rigLoaderLoadLibrary "Useragent"
if rigIsMobile() is TRUE then
put rigMobile() into tAgent
else if rigIsBrowser() is TRUE then
put rigBrowser() && rigBrowserVersion() into tAgent
else if rigIsRobot() is TRUE then
put rigRobot() into tAgent
else
put "Unidentified User Agent" into tAgent
end if
put tAgent & "<br />" & rigAgentPlatform() into gData["agentInfo"] -- Platform info (Windows, Linux, Mac, etc.)
Handler Reference
rigIsBrowser()
Returns TRUE/FALSE (boolean) if the user agent is a known web browser.
rigIsMobile()
Returns TRUE/FALSE (boolean) if the user agent is a known mobile device.
rigIsRobot()
Returns TRUE/FALSE (boolean) if the user agent is a known robot.
Note: The user agent library only contains the most common robot definitions. It is not a complete list of bots. There are hundreds of them so searching for each one would not be very efficient. If you find that some bots that commonly visit your site are missing from the list you can add them to your application/config/useragents.lc file.
rigIsReferral()
Returns TRUE/FALSE (boolean) if the user agent was referred from another site.
rigBrowser()
Returns a string containing the name of the web browser viewing your site.
rigBrowserVersion()
Returns a string containing the version number of the web browser viewing your site.
rigMobile()
Returns a string containing the name of the mobile device viewing your site.
rigRobot()
Returns a string containing the name of the robot viewing your site.
rigAgentPlatform()
Returns a string containing the platform viewing your site (Linux, Windows, OS X, etc.).
rigReferrer()
The referrer, if the user agent was referred from another site. Typically you'll test for this as follows:
if rigIsReferral() is TRUE then
put rigReferrer() into gData["referrer"]
end if
rigAgentString()
Returns a string containing the full user agent string. Typically it will be something like this:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.4) Gecko/20060613 Camino/1.0.2
rigAcceptLang()
Lets you determine if the user agent accepts a particular language. Example:
if rigAcceptLang("en") is TRUE then
put "You accept English!" into gData["acceptedLang"]
end if
Note: This function is not typically very reliable since some browsers do not provide language info, and even among those that do, it is not always accurate.
rigAcceptCharset()
Lets you determine if the user agent accepts a particular character set. Example:
if rigAcceptCharset("utf-8") is TRUE then
put "Your browser supports UTF-8!" into gData["acceptedCharset"]
end if
Note: This function is not typically very reliable since some browsers do not provide character-set info, and even among those that do, it is not always accurate. LiveCode Hosting is currently not supporting the $_Server variable HTTP_ACCEPT_CHARSET, so this function returns FALSE on this server.