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.iniAlthough 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:
- Libraries via Composer: tools like
matomo/device-detectororwhichbrowser/parserare more accurate, faster, and easily updated via project dependencies. - User-Agent Client Hints (UA-CH): the new HTTP standard for obtaining structured and reliable information directly from the browser.
- Feature Detection: use JavaScript (or
@supportsqueries in CSS) to check if a feature exists, rather than guessing the browser name.
Link to this FAQ:
Has this FAQ been helpful?