parsing php to get URL and physical path summary _php tips

Source: Internet
Author: User

Here I would like to summarize some of the information that gets the URL in the address bar and my path to the file that it belongs to:
Using $_server[] We can do a lot of things: it's an array of headers (headers), path information, and script locations, and the entities of the array are created by the Web server.
This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. You do not need to use global $_server in a function or method; Access it, just as you would with $HTTP _server_vars.
The $HTTP _server_vars contains the same information, but is not an automatic global variable . (Note: $HTTP _server_vars and $_server are different variables, PHP handles them in different ways.) If the register_globals directive is set, these variables are also available in all scripts, that is, the $_server and $HTTP _server_vars arrays are separated.
 
$_server[' Http_host ' gets the current requested HOST: header content
$_server[' php_self '] This is probably the most frequently used, it returns the file name of the page that is currently being invoked, and if it is http://localhost/test/2005/test.php, it will return/test/2005/ test.php
$_server[' Script_name '] it will return the path containing the current script. This is useful when the page needs to point to itself
$_server[' Script_filename '] it will return the absolute path information where the current file is located
$_server[' Request_uri ' returns the URI required to access this page, including the "/"

There are, of course, many path functions:
DirName (), returns the section of the directory in the path information, preceded by a "/"
BaseName () returns the basic file name portion of the path, and can, of course, set the suffix to control the output.
Realpath (), returns the absolutely normalized path of the path information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.