Page 533 - Beginning PHP 5.3
P. 533

Chapter 16: PHP and the Outside World

                             Variable                         Description
                               $_SERVER[ “ DOCUMENT_ROOT “            The absolute path to the document root folder of the Web
                                                    ]
                                                            site (for example:   /home/matt/mysite/htdocs )
                               $_SERVER[ “ HTTP_REFERER “            The referring URL, as sent by the browser in the  Referer
                                                   ]
                                                            HTTP header. (See the  “ Working with HTTP ”  section in
                                                            this chapter for more details)
                                $_SERVER[ “ HTTP_USER_AGENT “        The visitor ’ s browser information, such as name and
                                                      ]
                                                            version. (A nicer way to access this information is to use the
                                                            PEAR   Net_UserAgent_Detect  package, as described in
                                                            Chapter 15)

                                $_SERVER[ “ HTTPS “             true  if the script was accessed via HTTPS;  false  if
                                            ]
                                                            accessed via HTTP
                               $_SERVER[ “ PATH_INFO “            Any extra info appended onto the URL. For example, if the
                                                ]
                                                            script is accessed via the URL   http://www.example.com/
                                                            myscript.php/extra/info ) then  $_SERVER[ “ PATH_
                                                            INFO “   contains  /extra/info . (Not supported on all
                                                                 ]
                                                            servers)
                                $_SERVER[ “ PHP_SELF “            The URL of the currently running script, relative to the Web
                                               ]
                                                            site ’ s document root. For example:   /about/index.php
                               $_SERVER[ “ QUERY_STRING “            The query string in the URL of the request, if present (this
                                                   ]
                                                            is the string that appears after the    ‘ ? ’   in the URL)
                               $_SERVER[ “ REMOTE_ADDR “            The IP address of the visitor ’ s computer (or proxy server if
                                                  ]
                                                            the visitor is using one)
                                $_SERVER[ “ REMOTE_HOST “        The hostname of the visitor ’ s computer (or proxy server if
                                                  ]
                                                            the visitor is using one). Because this involves making a
                                                            DNS lookup it can have a performance hit on the server, so
                                                            many Web server applications disable this option by
                                                            default. However, you can use   gethostbyaddr()  to
                                                            manually retrieve the hostname from the IP address as
                                                            follows:   echo gethostbyaddr( $_SERVER[ “ REMOTE_
                                                            ADDR “ ] )
                                $_SERVER[ “ REQUEST_METHOD “            The request method used to access the script (such as  GET ,
                                                     ]
                                                              POST , or  HEAD )














                                                                                                         495





                                                                                                      9/21/09   9:15:38 AM
          c16.indd   495                                                                              9/21/09   9:15:38 AM
          c16.indd   495
   528   529   530   531   532   533   534   535   536   537   538