<HTML ><HEAD ><TITLE >get_browser</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Miscellaneous functions" HREF="ref.misc.html"><LINK REL="PREVIOUS" TITLE="exit" HREF="function.exit.html"><LINK REL="NEXT" TITLE="highlight_file" HREF="function.highlight-file.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.exit.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.highlight-file.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.get-browser" ></A >get_browser</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN55531" ></A ><P > (PHP 3, PHP 4 )</P >get_browser -- Tells what the user's browser is capable of </DIV ><DIV CLASS="refsect1" ><A NAME="AEN55534" ></A ><H2 >Description</H2 >object <B CLASS="methodname" >get_browser</B > ( [string user_agent])<BR ></BR ><P > <B CLASS="function" >get_browser()</B > attempts to determine the capabilities of the user's browser. This is done by looking up the browser's information in the <TT CLASS="filename" >browscap.ini</TT > file. By default, the value of <TT CLASS="varname" >HTTP_USER_AGENT</TT > is used; however, you can alter this (i.e., look up another browser's info) by passing the optional <TT CLASS="parameter" ><I >user_agent</I ></TT > parameter to <B CLASS="function" >get_browser()</B >. </P ><P > The information is returned in an <A HREF="language.types.object.html" ><B CLASS="type" >object</B ></A >, which will contain various data elements representing, for instance, the browser's major and minor version numbers and ID string; <TT CLASS="constant" ><B >TRUE</B ></TT >/<TT CLASS="constant" ><B >FALSE</B ></TT > values for features such as frames, JavaScript, and cookies; and so forth. </P ><P > While <TT CLASS="filename" >browscap.ini</TT > contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory. </P ><P > The following example shows how one might list all available information retrieved about the user's browser. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN55555" ></A ><P ><B >Example 1. <B CLASS="function" >get_browser()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php echo $_SERVER['HTTP_USER_AGENT'] . "<hr />\n"; $browser = get_browser(); foreach ($browser as $name => $value) { print "<b>$name</b> $value <br />\n"; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > The output of the above script would look something like this: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)<hr /> <b>browser_name_pattern:</b> Mozilla/4\.5.*<br /> <b>parent:</b> Netscape 4.0<br /> <b>platform:</b> Linux<br /> <b>majorver:</b> 4<br /> <b>minorver:</b> 5<br /> <b>browser:</b> Netscape<br /> <b>version:</b> 4<br /> <b>frames:</b> 1<br /> <b>tables:</b> 1<br /> <b>cookies:</b> 1<br /> <b>backgroundsounds:</b> <br /> <b>vbscript:</b> <br /> <b>javascript:</b> 1<br /> <b>javaapplets:</b> 1<br /> <b>activexcontrols:</b> <br /> <b>beta:</b> <br /> <b>crawler:</b> <br /> <b>authenticodeupdate:</b> <br /> <b>msn:</b> <br /></PRE ></TD ></TR ></TABLE ><P > In order for this to work, your <A HREF="ref.misc.html#ini.browscap" >browscap</A > configuration setting in <TT CLASS="filename" >php.ini</TT > must point to the correct location of the <TT CLASS="filename" >browscap.ini</TT > file on your system. <TT CLASS="filename" >browscap.ini</TT > is not bundled with PHP but you may find an up-to-date <A HREF="http://www.garykeith.com/browsers/downloads.asp" TARGET="_top" > browscap.ini file here</A >. By default, the <A HREF="ref.misc.html#ini.browscap" >browscap</A > directive is commented out. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > The <TT CLASS="literal" >cookies</TT > value simply means that the browser itself is capable of accepting cookies and does not mean the user has enabled the browser to accept cookies or not. The only way to test if cookies are accepted is to set one with <A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A >, reload, and check for the value. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > On versions older than PHP 4.0.6, you will have to pass the user agent in via the optional <TT CLASS="parameter" ><I >user_agent</I ></TT > parameter if the PHP directive <A HREF="configuration.directives.html#ini.register-globals" > register_globals</A > is <TT CLASS="literal" >off</TT >. In this case, you will pass in <TT CLASS="varname" >$HTTP_SERVER_VARS['HTTP_USER_AGENT']</TT >. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.exit.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.highlight-file.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >exit</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.misc.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >highlight_file</TD ></TR ></TABLE ></DIV ></BODY ></HTML >