User Agent Testing
Note: It is generally advisable not to use User Agent sniffing and it is generally advisable to attempt feature detection in other ways.
However where there is no other alternative Moodle provides the core_useragent class for the sniffing of the User Agents of supported browsers and clients.
This class contains static functions for availability of certain features based upon the user agent, and also functions for checking the name and version of certain browsers.
The following feature tests are available:
- supports_svg - Whether the browser supports SVG icons
- supports_json_contenttype - Whether the browser supports the JSON Content=type
- is_web_crawler - Whether the browser matches a known Web Crawler
Functions are also available to obtain additional information:
- get_device_type - The type of device (Desktop / Mobile / Tablet)
Further functions are available for checking the versions of other supported browsers.