Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

User Agent

From MoodleDocs

User Agent Testing

Warning

Note: It is generally advisable not to use User Agent sniffing and it is generally advisable to attempt feature detection in other ways.

About

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.

Available checks

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)
  • check_browser_operating_system

Further functions are available for checking the versions of other supported browsers.