Sinless server php. Superglobal array $_SERVER
$HTTP_SERVER_VARS [deleted]
(PHP 4 >= 4.1.0, PHP 5, PHP 7)
$_SERVER -- $HTTP_SERVER_VARS [deleted] — Information about the server and execution environment
Description
The $_SERVER variable is an array containing information such as script headers, paths, and locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of them; the server may omit some of them or provide others not listed here. However, many of these variables are present in the » CGI/1.1 specification, so you can expect them to be implemented in your particular web server.
The $HTTP_SERVER_VARS variable contains the same initial information, but it is not superglobal. (Note that $HTTP_SERVER_VARS and $_SERVER are different variables, so PHP treats them accordingly). Also note that "long arrays" were removed in PHP 5.4.0, so $HTTP_SERVER_VARS no longer exists.
Indexes
You may (or may not) find any of the following elements in the $_SERVER array. Note that few, if any, items will be available (or really make a difference) if PHP is running on the command line.
"PHP_SELF" The name of the script file that is currently running, relative to the document root. For example, $_SERVER["PHP_SELF"] in the script at http://example.com/foo/bar.php would be /foo/bar.php . The __FILE__ constant contains the full path and file name of the current (that is, connected) file. If PHP is running on the command line, this variable contains the name of the script, starting with PHP 4.3.0. Previously it was not available."argv" An array of arguments passed to the script. When the script is run on the command line, it gives C-like access to command line options. When called via the GET method, this array will contain the query string."argc" Contains the number of parameters passed to the script (if launched on the command line)."GATEWAY_INTERFACE" Contains the version of the CGI specification used by the server; For example" CGI/1.1". "SERVER_ADDR" IP address of the server on which the current script is running."SERVER_NAME" The name of the host on which the current script is running. If the script is running on a virtual host, this will contain the name defined for that virtual host."SERVER_SOFTWARE" The server identification string specified in the headers when a response to a request occurs."SERVER_PROTOCOL" The name and version of the information protocol through which the page was requested; For example " HTTP/1.0"; "REQUEST_METHOD" What method was used to request the page; For example " GET", "HEAD", "POST", "PUT".
"REQUEST_TIME" Timestamp of the start of the request. Available starting from PHP 5.1.0."REQUEST_TIME_FLOAT" Timestamp of the start of the request, accurate to microseconds. Available starting from PHP 5.4.0."QUERY_STRING" The query string, if any, that retrieved the page."DOCUMENT_ROOT" The document root directory in which the current script is executed is exactly the one specified in the server configuration file."HTTP_ACCEPT" Header content Accept: from the current request, if there is one." HTTP_ACCEPT_CHARSET " Header content Accept-Charset: from the current request, if there is one. For example: " iso-8859-1,*,utf-8". " HTTP_ACCEPT_ENCODING " Header content Accept-Encoding: gzip". " HTTP_ACCEPT_LANGUAGE " Header content Accept-Language: from the current request, if there is one. For example: " en". "HTTP_CONNECTION" Header content Connection: from the current request, if there is one. For example: " Keep-Alive". "HTTP_HOST" Header content Host: from the current request, if there is one."HTTP_REFERER" The address of the page (if any) that brought the user's browser to this page. This header is set by the user's web browser. Not all browsers install it and some allow you to change the contents of the HTTP_REFERER header as an additional feature. In a word, he really cannot be trusted." HTTP_USER_AGENT " Header content User-Agent: from the current request, if there is one. This line contains the browser that the user used to request this page. A typical example is the line: Mozilla/4.5 (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with the function get_browser() to adapt the output of your page to the capabilities of the user's browser"HTTPS" Accepts a non-empty value if the request was made via the HTTPS protocol.Comment:
The PHP script exits after sending the headers (that is, after performing any output without buffering the output), if the request was made using the method HEAD.
"REMOTE_ADDR" The IP address from which the user is viewing the current page."REMOTE_HOST" The remote host from which the user is viewing the current page. Reverse DNS lookup is based on the value of the REMOTE_ADDR variable.Comment: Note that when using ISAPI with IIS the value will be off, if the request was not made via HTTPS.
"REMOTE_PORT" The port on the remote machine that is used to communicate with the web server."REMOTE_USER" Authenticated user."REDIRECT_REMOTE_USER" The authenticated user if the request was redirected internally."SCRIPT_FILENAME"Comment: Your web server must be configured to create this variable. For example, in Apache you need the presence of the directive HostnameLookups On in the httpd.conf file so that this variable is created. see also gethostbyaddr().
The absolute path to the script that is currently executing.
"SERVER_ADMIN" This variable gets its value (for Apache) from a directive in the server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host."SERVER_PORT" The port on the server computer that the web server uses to connect. For default settings, the value will be " 80 "; using SLL, for example, this value will be as configured for secure HTTP connections.Comment:
If the script is run on the command line (CLI) using a relative path such as file.php or ../file.php , the $_SERVER["SCRIPT_FILENAME"] variable will contain the relative path specified by the user.
"SERVER_SIGNATURE" A string containing the server version and virtual host name that is added to server-generated pages if enabled."PATH_TRANSLATED" Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.Comment: To get a physical (real) port in Apache 2, you need to install UseCanonicalName = On And UseCanonicalPhysicalPort = On, otherwise this value may be replaced and not return the real value of the physical port. Relying on this value is unsafe in the context of applications that require enhanced security.
"SCRIPT_NAME" Contains the path to the currently executing script. This is useful for pages that need to point to themselves. The __FILE__ constant contains the full path and name of the current (i.e. included) file."REQUEST_URI" The URI that was passed in order to access this page. For example, " /index.html". "PHP_AUTH_DIGEST" When performing HTTP Digest authentication, this variable is assigned the "Authorization" header, which is sent by the client (this must then be used for appropriate validation)."PHP_AUTH_USER" When HTTP authentication is performed, this variable is set to the username provided by the user."PHP_AUTH_PW" When HTTP authentication is performed, this variable is set to the password provided by the user."AUTH_TYPE" When HTTP authentication is performed, this variable is set to the authentication type that is being used."PATH_INFO" Contains any user-supplied path contained after the script name but before the query string, if available. For example, if the current script is requested by the URL http://www.example.com/php/path_info.php/some/stuff?foo=bar , then the $_SERVER["PATH_INFO"] variable will contain /some/stuff?>Comment: As of PHP 4.3.2, the PATH_TRANSLATED variable is no longer set implicitly in the Apache 2 SAPI, compared to Apache version 1 where it was set to the same value as the SCRIPT_FILENAME variable when not in use by Apache. This change was made to comply with the CGI specification, where the PATH_TRANSLATED variable should only exist when PATH_INFO is defined. Apache 2 users can use the directive AcceptPathInfo = On in the httpd.conf configuration file to set the PATH_INFO variable.
The result of running this example will be something like this.
First, we will improve the registration page by adding the ability to upload an avatar. The source image must be in jpg, gif or png format. It should also be no more than 2 MB. Don't worry, after it is compressed by the script, the avatar size will be about 3 kb and jpg format. Open the page reg.php and add it in the tag < form> line enctype="multipart/form-data", as in the example: