Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Using the browscap.ini file

This guide covers "browscap.ini", a legacy configuration file used by PHP to identify web browser characteristics (name, version, capabilities, OS) from their User-Agent string.

The use of browscap.ini is now considered obsolete for new projects due to its negative impact on performance and the evolution of web standards.

 

Information about the file and legacy usage

For the native PHP function get_browser() to work, it must point to an up-to-date browscap.ini file. The default path on servers is usually:

/opt/php/lib/php/browscap.ini

Although not recommended for production due to the file size (several MB to load into memory), you can view its content via this script:

<?php
header("Content-type: text/plain");
if (file_exists("/opt/php/lib/php/browscap.ini")) {
    echo file_get_contents("/opt/php/lib/php/browscap.ini");
} else {
    echo "Fichier introuvable.";
}
?>

 

Recommended modern alternatives

For current projects, developers prefer the following solutions:

  1. Libraries via Composer: tools like matomo/device-detector or whichbrowser/parser are more accurate, faster, and easily updated via project dependencies.
  2. User-Agent Client Hints (UA-CH): the new HTTP standard for obtaining structured and reliable information directly from the browser.
  3. Feature Detection: use JavaScript (or @supports queries in CSS) to check if a feature exists, rather than guessing the browser name.

Has this FAQ been helpful?