PHP constants and variables environment variables

Environment variables We mainly use two environment variables, $_SERVER and $_ENV.

However, $_ENV is gradually abandoned by new versions of PHP.

[Key Points] Know where to check the name (key) and value (value) of environment variables, and remember and write down several commonly used environment variables.

Check the environment variables. We learned this on the first day of learning PHP:

In fact, environment variables are not something that you need to memorize. I know where to find the key of the environment variable. Just sum the value.
We learned phpinfo(); and printed out a bunch of messy things. Let’s learn about the environment variables part of it today.

In the URL where you execute phpinfo();, pull down the page and turn the page to see if you can find the part in the screenshot:

2015-08-02_55bdbf7ec59b9.png

_SERVER['middle value'], we need to understand the meaning.

If we need to display where the phpinfo(); page file we are currently accessing is located, we can execute:

Let’s learn about the key names and values of some commonly used environment variables. Meaning:

Key name Meaning
$_SERVER[ "REQUEST_METHOD"] Method to request the current PHP page
$_SERVER["REQUEST_URI"] Requested URI
$_SERVER["SERVER_SOFTWARE"] What kind of server are you using
$_SERVER["REMOTE_ADDR"] Customer’s IP address
$_SERVER["SERVER_ADDR"] Current server’s IP address
$_SERVER[ "SCRIPT_FILENAME"] The path of the main requested file
$_SERVER["HTTP_USER_AGENT"] The computer and browser currently accessing this URL Situation
$_SERVER["HTTP_REFERER"] Superior source (the address from which the user entered the current web page)
$_SERVER["REQUEST_TIME"] Current time


URI and URL are both web addresses, but URL contains the host address part, while URI does not contain the host address part, for example:
//m.sbmmt.com/ abc.php?username=php The above is a URL (Uniform Resource Locator), and the URI is the part without the host and (http://)

protocol:
abc.php?username=php

time
Pronunciation: [taɪm]
Explanation: time

file
Pronunciation: [faɪl]
Explanation: file

name
Pronunciation: [neɪm]
Explanation: Name

sowftware
Pronunciation: [ˈsɔ:ftwer]
Explanation: Software

address (abbreviated addr)
Pronunciation: [ˈædres]
Explanation: Address

remote
Pronunciation: [rɪˈmoʊt]
Explanation: Remote, remote

server
Pronunciation: [ˈsɜ:və(r)]
Explanation: service, server

method
Pronunciation: [ˈmɛθəd]
Explanation: method

port
Pronunciation: [pɔ:rt]
Explanation: Port


Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!