📜 ⬆️ ⬇️

What can PHP know about the visitor's browser?

What is it about?


Is it possible to find out more detailed information about the visitor's browser besides the line contained in $ _SERVER ["HTTP_USER_AGENT"] : does java, applets, style sheets and frames support? Or maybe it all went guglobot?


Prehistory


The customer wanted it to show his favorite logo with a spark of light running through it when entering the site ... I couldn’t persuade the person to abandon this idea, but in the end we decided that this joy would be displayed only once, and only when entering home page. If a person came to the site from a search engine, he immediately goes to the page. If he manually enters the address into the browser, he is redirected to the page with the animation. After a successful display, a marker is written in the cookie, and the video is no longer loaded. But ... If a person does not go to the site, but a search engine, he will not write himself a cookie. Therefore, he will always stumble upon a page with animation, and we will not see ourselves in the search engine results. And why should the company see the company's logo? :)

How can I find out anything about the client browser


The problem was finally solved by searching for the substring of spider names of several well-known search engines in the $ _SERVER ["HTTP_USER_AGENT"] variable. But before that, I walked around mana and found an interesting function get_browser () . She knows how to produce an array of browser parameters of our site’s guest, but I still don’t understand the purpose of which is half :) The only subtlety of this function is that it requires a fresh version of browscap.ini file on the host, as well as php.ini settings . It is obvious that our lazy (please do not be offended) admin administrators constantly update this file, so they usually block it and the function is simply not available. You can check this by looking in phpinfo () , finding the browscap directive there , and not at all surprised that “no value” proudly flaunts in front of it, proceed to the next paragraph.
')

What to do


First we need the browscap.ini file itself . It can be downloaded from http://browsers.garykeith.com/ . Maybe it is somewhere else, but this source is recommended for downloading by PHP itself, so we use it.
The question arises: where do we actually attach it now? The admin will not allow us to the server, and will not allow picking in the settings. In this, it would be necessary to look for another option. And there were two of them on the net.

Here are the detailed and simple instructions for launching. In short, it remains to download the right library, connect to the right place, and call the appropriate function. For the Browser Capabilities PHP Project, the call looks like this:

if(ini_get('browscap'))
{
//

/* */
//
echo " - !";
/* - :)*/

$browserInfo=get_browser();

}
else
{
//
require_once('browscap.php');
$bc = new Browscap('path/to/the/cache/dir');
$browserInfo=$bc->getBrowser();

}


as a result, we get about the following
stdClass Object
(
[browser_name] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18
[browser_name_regex] => ^mozilla/5\.0 \(macintosh; .; .*mac os x.*\) applewebkit/.* \(.*\) version/3\.1.* safari/.*$
[browser_name_pattern] => Mozilla/5.0 (Macintosh; ?; *Mac OS X*) AppleWebKit/* (*) Version/3.1* Safari/*
[Parent] => Safari 3.1
[Platform] => MacOSX
[Browser] => Safari
[Version] => 3.1
[MajorVer] => 3
[MinorVer] => 1
[Frames] => 1
[IFrames] => 1
[Tables] => 1
[Cookies] => 1
[BackgroundSounds] => 1
[JavaApplets] => 1
[JavaScript] => 1
[CSS] => 2
[CssVersion] => 2
[supportsCSS] => 1
[Alpha] =>
[Beta] =>
[Win16] =>
[Win32] =>
[Win64] =>
[AuthenticodeUpdate] =>
[CDF] =>
[VBScript] =>
[ActiveXControls] =>
[Stripper] =>
[isBanned] =>
[WAP] =>
[isMobileDevice] =>
[isSyndicationReader] =>
[Crawler] =>
[AOL] =>
[aolVersion] => 0
[netCLR] =>
[ClrVersion] => 0
)


UPD. The data obtained only indicate that the browser supports some technology, and not about its availability, since the browscap.ini file is essentially a database of all web clients, in which, by the value of the browser’s User-Agent, information about the technologies supported by this browser is provided. That is, for modern browsers, when cookies and Java are disabled, the corresponding parameters will still return a unit.

Where to use this function, I hope everyone will find for himself :)

Source: https://habr.com/ru/post/38359/


All Articles