The user's browser is given in the environment variable $HTTP_USER_AGENT.
However, the number of different possible values for this is massive, so in
order to decide, for example, whether to send the client Javascript or not,
you'll need access to a database of all the possible browsers that exist.
Fortunately, this has been done for you.
PHP has a function, get_browser(), which returns a browser object, which I
think will do what you're after.
You need a browser capabilities file, such as the browscap.ini which ships
with Microsoft's IIS. Free versions are available from
http://php.netvision.net.il/browscap/, and
http://www.cyscape.com/asp/browscap. The most up to date and reliable one,
however, is probably Juan T Llibre's, which is kept very complete and
up-to-date and is available from http://asptracker.com/browscap.zip.
The browscap file contains information about what types of data a large
number of different browsers are capable of displaying and running. The file
format was developed by Microsoft for ASP, but it's such a neat idea that
PHP has adopted it.
You'll need to tell PHP where your browscap.ini file is, which is done by
including the following line in php.ini:
browscap "C:\WINNT\system32\inetsrv\browscap.ini"
(replacing the path with the one to browscap on your system. The path shown
is to the browscap Microsoft provides with IIS on Windows NT or 2000)
The object will then have data fields which contain information about the
browser of the user viewing the page. The names of these will be those used
in the browscap file. For example:
some variables containg information about the browser:
browser (the name of the browser, e.g. IE or Netscape)
version (the full version number, e.g. 4.00)
platform (the OS the browser's running on, e.g. Win98, Mac68K, etc.)
majorver (the whole part of the version number, e.g. 4)
minorver (the decimal part of the version number, e.g. 0)
A bunch of variables which are boolean values - true if the browser supports
it, false if not, such as:
frames
tables
cookies
vbscript
javascript
javaapplets
The PHP manual page for get_browser() is:
http://www.php.net/manual/function.get-browser.php
Microsoft's information on browscap.ini files is at
http://msdn.microsoft.com/library/psdk/iisref/comp1g11.htm
Hope this helps,
regards,
James
> -----Original Message-----
> From: Rodney Lam [mailto:rodney@r...]
> Sent: 05 August 2000 01:00
> To: professional php
> Subject: [pro_php] detecting the browser
>
>
> can php detect the browser's information (such as which
> browser is the user
> using.)?
>
> if yes, which function should I use?
>
> Thx a lot~!
> Rodney.
>
> ---
> Do you know what you want from this list? How would you
> provide programmers with the solutions they need? If you have
> the answers, and are willing to work in Birmingham (UK), then
> you could be a List Manager. Please send CVs and a covering
> letter to listsupport@p... for further information.
>