Base de conhecimento
1000 perguntas frequentes, 500 tutoriais e vídeos explicativos. Aqui, você encontra apenas soluções!
Use the browscap.ini file
This guide explains the role of the browscap.ini file, which is used by PHP to identify certain characteristics of a browser, such as Brave, Chrome, Edge, Firefox, Opera, Safari… (name, version, operating system, and capabilities) based on its HTTP User-Agent header.
The use of browscap.ini is now mainly intended to ensure compatibility with existing applications. For new developments, more modern methods are generally preferred.
Using with the get_browser() function
The native PHP get_browser() function requires access to an up-to-date browscap.ini file in order to identify the characteristics of the browser that made the request.
On Infomaniak Web Hosting, this file is generally available at the following location:
/opt/php/lib/php/browscap.iniIf necessary, you can check its content using the following script:
<?php
header('Content-Type: text/plain');
$file = '/opt/php/lib/php/browscap.ini';
if (file_exists($file)) {
echo file_get_contents($file);
} else {
echo 'File not found.';
}Due to its size and the cost of loading it, using browscap.ini can impact the performance of applications that rely on get_browser().
Recommended alternatives
For new projects, it is generally preferable to use solutions that are better suited to current web development practices:
- PHP libraries installed with Composer, such as
matomo/device-detectororwhichbrowser/parser, which offer regularly updated and more comprehensive browser and device detection. - User-Agent Client Hints (UA-CH), when supported by the browser, to obtain structured information via the mechanisms provided by current HTTP standards.
- Feature Detection, by directly checking the availability of a feature (e.g., in JavaScript or with the CSS rule
@supports) rather than inferring behavior based on the browser used.
Link para esta FAQ: https://faq.infomaniak.com/505
Esta seção de perguntas frequentes foi útil?