Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 726

php-manual-en-4.3.0-2mdk.noarch.rpm

<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&nbsp;--&nbsp;
     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
>&#13;     <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
>&#13;     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
>&#13;     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
>&#13;     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"
>&#60;?php
echo $_SERVER['HTTP_USER_AGENT'] . "&#60;hr /&#62;\n";

$browser = get_browser();

foreach ($browser as $name =&#62; $value) {
    print "&#60;b&#62;$name&#60;/b&#62; $value &#60;br /&#62;\n";
}

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     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)&#60;hr /&#62;
&#60;b&#62;browser_name_pattern:&#60;/b&#62; Mozilla/4\.5.*&#60;br /&#62;
&#60;b&#62;parent:&#60;/b&#62; Netscape 4.0&#60;br /&#62;
&#60;b&#62;platform:&#60;/b&#62; Linux&#60;br /&#62;
&#60;b&#62;majorver:&#60;/b&#62; 4&#60;br /&#62;
&#60;b&#62;minorver:&#60;/b&#62; 5&#60;br /&#62;
&#60;b&#62;browser:&#60;/b&#62; Netscape&#60;br /&#62;
&#60;b&#62;version:&#60;/b&#62; 4&#60;br /&#62;
&#60;b&#62;frames:&#60;/b&#62; 1&#60;br /&#62;
&#60;b&#62;tables:&#60;/b&#62; 1&#60;br /&#62;
&#60;b&#62;cookies:&#60;/b&#62; 1&#60;br /&#62;
&#60;b&#62;backgroundsounds:&#60;/b&#62; &#60;br /&#62;
&#60;b&#62;vbscript:&#60;/b&#62; &#60;br /&#62;
&#60;b&#62;javascript:&#60;/b&#62; 1&#60;br /&#62;
&#60;b&#62;javaapplets:&#60;/b&#62; 1&#60;br /&#62;
&#60;b&#62;activexcontrols:&#60;/b&#62; &#60;br /&#62;
&#60;b&#62;beta:&#60;/b&#62; &#60;br /&#62;
&#60;b&#62;crawler:&#60;/b&#62; &#60;br /&#62;
&#60;b&#62;authenticodeupdate:&#60;/b&#62; &#60;br /&#62;
&#60;b&#62;msn:&#60;/b&#62; &#60;br /&#62;</PRE
></TD
></TR
></TABLE
><P
>&#13;     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"
>&#13;     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"
>&#13;      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
>