Which browser is being used?
Posted by enquirer (enquirer), 31 December 2002How do I tell which browser my web site visitor is using so that I can tailor my HTML to suit?
Posted by admin (Graham Ellis), 31 December 2002PHP has a built in get_browser function but it isn't just as simple as calling that function. A browser capability file called browscap.ini is required, and reference has to be made to that file in your php.ini file. The browser capability file is NOT supplied with the main PHP distribution; that's said to be because of copyright reasons, but personally I suspect it's because browsers change so much that it's simply out of date too fast and the PHP folks don't want to get blamed fopr any errors.
If you want to use browscap, you might like to try the following locations for the file:
which however are all incomplete or out of date to some extent.
As an alternative, you may wish to return to "first principles" and write your own simple function based on the $HTTP_USER_AGENT variable, from which you can quickly work out if you have a copy
of Internet Explorer (look for the string MSIE), Netscape, or some other browser, and the version number.
Here's a sample web page (on a system onto which we have installed a browscap file) which shows both information sources in use.
And here are the results of calling up the page from an Internet Explorer browser running on Mac OS X 10.1
Posted by John_Moylan (jfp), 2 January 2003...and there just happens to be a recipe in the pdf of the sample chapter of the PHP cookbook.
It does look good, I should just get it instead of waiting for reviews, after all, it is an O'Reilly book
Which leads nicely onto my next post.
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho