What can PHP learn 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 it support Java, applets, style sheets and frames? Or maybe it’s googlobot in general?
Prehistory
I wanted the customer to see his favorite logo with a spark of light running through it on the site ... I still 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 animation page. After a successful display, a marker is written in the cookie and the video is no longer loaded. But ... If the site is visited not by a person, but by a search engine, then he will not write cookies to himself. Therefore, he will always come across an animation page, and we won’t see ourselves in the search engine results. And why should a search engine see a company logo :)
How can I find out something about the client’s browser
The problem was eventually solved by searching for a substring of the names of spiders of several well-known search engines in the variable $ _SERVER ["HTTP_USER_AGENT"] . But before that, I walked around mana and discovered an interesting get_browser () function . It can issue an array of browser parameters for the guest of our site, half of which, however, I still don’t understand :) The only subtlety of this function is that it requires a fresh version of the browscap.ini file on the host , as well as php.ini settings . It is obvious that our lazy (please do not be offended) administrators broke constantly update this file, so this is usually killed and the function is simply not available. You can verify this by looking at phpinfo ()having found the browscap directive there , and not at all surprised that the inscription “no value” proudly flaunts across from it, proceed to read 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 download by PHP itself, so we use it.
The question arises: where are we, in fact, now to attach it? The admin will not let us in to the server, and it won’t let us tinker with the settings. Therefore, one would have to look for another option. And there were two of them in the network.
Here are detailed and simple startup instructions. In short, it remains to download the desired library, connect to the right place, and call the corresponding function. For Browser Capabilities PHP Project, the call looks like this: as a result, we get something like the following UPD. The data obtained only indicates that the browser supports a certain technology, and not about its availability, since the browscap.ini file is essentially a database of all web clients, which, according to the value of the User-Agent of the browser, provides information about the technologies supported by this browser. That is, for modern browsers with cookies turned off and Java, the corresponding parameters will still return one.
if(ini_get('browscap'))
{
//неленивые админы попались
/* старт шутки */
//вероятность выполнение участка кода стремится к нулю поэтому пишем сюда
echo "Начальство - ты меня задрало!";
/* конец шутки - всем смеяться :)*/
$browserInfo=get_browser();
}
else
{
//используем нашу библиотеку
require_once('browscap.php');
$bc = new Browscap('path/to/the/cache/dir');
$browserInfo=$bc->getBrowser();
}
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
)
Where to use this function, I hope everyone will find for themselves :)