<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >get_browser</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" 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="__halt_compiler" HREF="function.halt-compiler.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></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 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.exit.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.halt-compiler.html" ACCESSKEY="N" >下一页</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="AEN125478" ></A ><P > (PHP 3, PHP 4, PHP 5)</P >get_browser -- Tells what the user's browser is capable of</DIV ><DIV CLASS="refsect1" ><A NAME="AEN125481" ></A ><H2 >说明</H2 >mixed <B CLASS="methodname" >get_browser</B > ( [string user_agent [, bool return_array]] )<BR ></BR ><P > Attempts to determine the capabilities of the user's browser, by looking up the browser's information in the <TT CLASS="filename" >browscap.ini</TT > file. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN125494" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >user_agent</CODE ></DT ><DD ><P > The User Agent to be analyzed. By default, the value of HTTP User-Agent header is used; however, you can alter this (i.e., look up another browser's info) by passing this parameter. </P ><P > You can bypass this parameter with a <TT CLASS="constant" ><B >NULL</B ></TT > value. </P ></DD ><DT ><CODE CLASS="parameter" >return_array</CODE ></DT ><DD ><P > If set to <TT CLASS="constant" ><B >TRUE</B ></TT >, this function will return an <A HREF="language.types.array.html" ><B CLASS="type" >array</B ></A > instead of an <A HREF="language.types.object.html" ><B CLASS="type" >object</B ></A >. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN125513" ></A ><H2 >返回值</H2 ><P > The information is returned in an object or an array 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 > 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 ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN125521" ></A ><H2 >更新日志</H2 ><P > <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN125524" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >版本</TH ><TH >说明</TH ></TR ></THEAD ><TBODY ><TR ><TD >4.3.2</TD ><TD > The optional parameter <CODE CLASS="parameter" >return_array</CODE > was added. </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN125535" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN125538" ></A ><P ><B >例 1. Listing all information about the users browser</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">echo </font><font color="#0000BB">$_SERVER</font><font color="#007700">[</font><font color="#DD0000">'HTTP_USER_AGENT'</font><font color="#007700">] . </font><font color="#DD0000">"\n\n"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$browser </font><font color="#007700">= </font><font color="#0000BB">get_browser</font><font color="#007700">(</font><font color="#0000BB">null</font><font color="#007700">, </font><font color="#0000BB">true</font><font color="#007700">);<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$browser</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >上例的输出类似于:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3 Array ( [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$ [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9* [parent] => Firefox 0.9 [platform] => WinXP [browser] => Firefox [version] => 0.9 [majorver] => 0 [minorver] => 9 [css] => 2 [frames] => 1 [iframes] => 1 [tables] => 1 [cookies] => 1 [backgroundsounds] => [vbscript] => [javascript] => 1 [javaapplets] => 1 [activexcontrols] => [cdf] => [aol] => [beta] => 1 [win16] => [crawler] => [stripper] => [wap] => [netclr] => )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN125543" ></A ><H2 >注释</H2 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > 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. </P ><P > <TT CLASS="filename" >browscap.ini</TT > is not bundled with PHP, but you may find an up-to-date <A HREF="http://browsers.garykeith.com/downloads.asp" TARGET="_top" >php_browscap.ini</A > file here. </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 ></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" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.halt-compiler.html" ACCESSKEY="N" >下一页</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" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >__halt_compiler</TD ></TR ></TABLE ></DIV ></BODY ></HTML >