Summary of URL and physical path obtained in PHP

Source: Internet
Author: User
Here I want to summarize some information about the path where the URL and file in the address bar belong: Application $ _ SERVER [] we can do a lot of things: it is an array containing headers, path information, and script status.

Here I want to summarize some information about the path where the URL and file in the address bar belong to me:

The application $ _ SERVER [] can accomplish many things: it is an array containing headers, path information, and script status. the array entity is created by the web SERVER.

This is a "superglobal", or it can be described as an active global variable. This only means that it is valid in all scripts. You do not need to apply global $ _ SERVER; to access a function or method, just like applying $ HTTP_SERVER_VARS. $ HTTP_SERVER_VARS contains the same information, but it is not an active global variable. (Note: $ HTTP_SERVER_VARS and $ _ SERVER are different variables. PHP processes them differently .) If the register_globals command is set, these variables are also available in all scripts; that is, the $ _ SERVER and $ HTTP_SERVER_VARS arrays are respectively set.

$ _ SERVER ['http _ host'] obtains the requested HOST: header content
$ _ SERVER ['php _ SELF '], which is probably the most frequently used one. it returns the name of the currently called page, for example, http: // localhost/test/2005/test. php,/test/2005/test will be returned. php

$ _ SERVER ['script _ name'] returns the path containing the current SCRIPT. This is useful when the page needs to point to itself.

$ _ SERVER ['script _ filename'], which returns the path of the current file.

$ _ SERVER ['request _ URI '] returns the URI required to visit this page, including '/'

Of course there are many path functions:

Dirname (), returns the directory section in the path information, with '/' in front


Basename () returns the basic file name part in the path. you can also set a suffix to hold the output.

Realpath (): returns the 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.