Home > Backend Development > PHP Tutorial > Summary of obtaining url and physical path in parsing php_PHP tutorial

Summary of obtaining url and physical path in parsing php_PHP tutorial

WBOY
Release: 2016-07-21 15:04:16
Original
862 people have browsed it

Here I would like to summarize some information about getting the URL in the address bar and the path to which the file belongs:
Using $_SERVER[ ] we can accomplish many things Thing: It is an array containing headers, path information and script location. The entities of the array are created by the web server.
This is a "superglobal", or can be described as an automatic global variable. This just means that it works in all scripts. You do not need to use global $_SERVER; to access it within a function or method, as you would with $HTTP_SERVER_VARS.
$HTTP_SERVER_VARS contains the same information, but is not an automatic global variable. (Note: $HTTP_SERVER_VARS and $_SERVER are different variables, and PHP handles them differently.) These variables are also available in all scripts if the register_globals directive is set; that is, the $_SERVER and $HTTP_SERVER_VARS arrays are separated .
 
$_SERVER['HTTP_HOST'] Gets the Host: header content of the current request
$_SERVER['PHP_SELF'] This may be the one we use most often. It returns the information of the currently called page. The file name, if it is http://localhost/test/2005/test.php, will return /test/2005/test.php
$_SERVER['SCRIPT_NAME'] which 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 " /"

Of course there are many path functions:
dirname(), which returns the directory part of the path information, preceded by
basename( with "/" ) returns the basic file name part of the path. Of course, the suffix can also be set to control the output.
realpath(), returns the absolutely normalized path of the path information

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327784.htmlTechArticleHere I would like to summarize some information about getting the URL in the address bar and the path to which the file belongs: Use $ _SERVER[ ] We can do many things: it is a header containing headers...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template