Summary of Obtaining Url and Physical Path in PHP_PHP Tutorial

WBOY
Release: 2016-07-20 11:05:51
Original
760 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: it is a header containing ( headers), an array of 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 current calling page. File name, if it is http://localhost/test/2005/test.php, then it will return /test/2005/test.php

$_SERVER['SCRIPT_NAME'] which will return the current script. path. This is very 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 location where this page is accessed The required URI, including "/"


Of course there are many path functions:

dirname(), which returns the directory part of the path information, preceded by "/"


basename() returns the basic file name part of the path. Of course, you can also set the suffix to control the output.

realpath(), returns the absolutely normalized path of the path information


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445103.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