Main Content

What features does this visitors browser support? (PHP)

Archive - Originally posted on "The Horse's Mouth" - 2009-04-22 23:28:15 - Graham Ellis

Does this visitor's web site support CSS? Is this visitor a robot? Should I send out frames? There are the sorts of questions that you may want to ask in a PHP page .... and PHP supports the get_browser function which can tell you ... or which can tell, most of the time, once you have it configured.

The browscap.ini file that the function needs doe NOT ship with PHP. When you think about it, there's a certain logic to that as the browser database has to be updated far more frequently that PHP, so a separate distribution channel is sensible. Latest download from http://browsers.garykeith.com/downloads.asp. Then you need to configure it into your PHP (i.e. tell your PHP where to find the file ... and I've done that on our server by adding the following line to the end of my php.ini file:
browscap = /home/wellho/include/browscap.ini
And then stopping and restarting httpd.

And get_browser will now work. See it run at http://www.wellho.net/demo/gbs.php and see the source code of my demonstration at http://www.wellho.net/resources/ex.php4?item=h304/gbs.php.




Two more new browser type demos in PHP ... see here for a sorted list of the browsers that people used for the first 1000 hits on our site yesterday, and here for a demo that send out a graphic to a real user, but a descriptive alternative to a robot. That's a cheap and cheerful way of doing some of the things that I mention with get_browser and may be all you need. There are links to source on both of these examples.