📄 function.get-browser.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Tells what the user's browser is capable of</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.exit.html">exit</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.halt-compiler.html">__halt_compiler</a></div> <div class="up"><a href="ref.misc.html">Misc. Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.get-browser" class="refentry"> <div class="refnamediv"> <h1 class="refname">get_browser</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">get_browser</span> — <span class="dc-title">Tells what the user's browser is capable of</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>get_browser</b></b></span> ([ <span class="methodparam"><span class="type">string</span> <tt class="parameter">$user_agent</tt></span> [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$return_array</tt></span> ]] )</div> <p class="para rdfs-comment"> Attempts to determine the capabilities of the user's browser, by looking up the browser's information in the <var class="filename">browscap.ini</var> file. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">user_agent</tt></i></span> <dd> <p class="para"> 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 class="para"> You can bypass this parameter with a <b><tt>NULL</tt></b> value. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">return_array</tt></i></span> <dd> <p class="para"> If set to <b><tt>TRUE</tt></b>, this function will return an <a href="language.types.array.html" class="type array">array</a> instead of an <a href="language.types.object.html" class="type object">object</a>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> 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; <b><tt>TRUE</tt></b>/<b><tt>FALSE</tt></b> values for features such as frames, JavaScript, and cookies; and so forth. </p> <p class="para"> The <i>cookies</i> 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" class="function">setcookie()</a>, reload, and check for the value. </p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">4.3.2</td> <td colspan="1" rowspan="1" align="left"> The optional parameter <i><tt class="parameter">return_array</tt></i> was added. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Listing all information about the users browser</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'HTTP_USER_AGENT'</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$browser </span><span style="color: #007700">= </span><span style="color: #0000BB">get_browser</span><span style="color: #007700">(</span><span style="color: #0000BB">null</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$browser</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3Array( [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></div> </pre></div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: In order for this to work, your <a href="misc.configuration.html#ini.browscap" class="link">browscap</a> configuration setting in <var class="filename">php.ini</var> must point to the correct location of the <var class="filename">browscap.ini</var> file on your system. <br /> <var class="filename">browscap.ini</var> is not bundled with PHP, but you may find an up-to-date <a href="http://browsers.garykeith.com/downloads.asp" class="link external">» php_browscap.ini</a> file here. <br /> While <var class="filename">browscap.ini</var> contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory. <br /> </p></blockquote> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.exit.html">exit</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.halt-compiler.html">__halt_compiler</a></div> <div class="up"><a href="ref.misc.html">Misc. Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -