Sinless server php. What is the difference between HTTP_HOST and SERVER_NAME in PHP? Full address to the script

Sinless server php.  What is the difference between HTTP_HOST and SERVER_NAME in PHP?  Full address to the script
Sinless server php. What is the difference between HTTP_HOST and SERVER_NAME in PHP? Full address to the script
$HTTP_SERVER_VARS [deleted]

(PHP 4 >= 4.1.0, PHP 5, PHP 7)

$_SERVER -- $HTTP_SERVER_VARS [removed] - Information about the server and runtime 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. 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 " Host name on which the current script is running. If the script is running on a virtual host, this will contain the name defined for it 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 " SERVER_SOFTWARE " The server identification string specified in the headers when a response to a request occurs..

HEAD POST PUT Note: 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 "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 configuration file server. " HTTP_ACCEPT " Header content Accept: from the current request, if there is one." HTTP_ACCEPT_CHARSET " Header content Accept-Charset: Accept: from the current request, if there is one. For example: " iso-8859-1,*,utf-8 "." HTTP_ACCEPT_ENCODING " Header Contents Accept-Encoding: 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 get_browser() function to tailor the output of your page to the user's browser capabilities " HTTPS " Accepts a non-empty value if the request was made via the HTTPS protocol.

Note: Please note that when using ISAPI with IIS the value will be off, if the request was not made via HTTPS.

"REMOTE_ADDR" 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. Note: 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() . "REMOTE_PORT" The port on the remote machine that is used to communicate with the web server."REMOTE_USER" Authenticated user.

"; " REQUEST_METHOD " What method was used to request the page; for example "

" REDIRECT_REMOTE_USER " The authenticated user if the request was redirected internally.

"SCRIPT_FILENAME" 80 The absolute path to the script that is in

this moment is being performed. 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_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 used by the web server to connect.

" SERVER_SIGNATURE " A string containing the server version and virtual host name, which are appended 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. Note: 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 used 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. "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, "

One of the coolest innovations in PHP 5.4 is the built-in server, created specifically for development and testing. Now you can write and test your code without having a full web server - just start the built-in server, test your code, and shut it down when you're done.
The server also provides the opportunity for creative use. For example, you can distribute a portable web application on CD or USB, or even as a desktop application built in PHP without using GTK or other graphics libraries.

The PHP manual emphasizes that the built-in server is intended for development and it is recommended not to use it on a production server. There are no INI directives responsible for the server (except for coloring output in the console), and it seems that the main idea of ​​​​the documentation is: “we now also have Web server, leave us alone."
Despite this, I believe that an embedded server can be a valuable tool for development and testing. For example, on my machine I use Apache pre-installed with a custom configuration that suits me, but sometimes I want to try some new Web applications. With a built-in web server, I can test the application directly from the downloads folder or temporary folder and move it to the regular environment only when necessary.
But to begin with, it is not so simple, because many written applications use .htaccess and mod_rewrite. But I'm sure someone (maybe one of you, why not?) will write an adapter for this, and I'd like to be the first to test it.
In this article, I'll explain some basic uses of the embedded server and show you how to make it useful for development and testing.

We use the built-in server So, to use the server we need PHP 5.4 or higher. To check the PHP version, run:
php -v
You can also determine whether the server is available in your build by running:
php -h
and find there a description of the "-S" and "-t" parameters, which are used only for the server.
To test the server, you can create an index.php file in the current directory, which will contain a call to the phpinfo() function and then start the server:
$ php -S 127.0.0.1:8080 PHP 5.4.0RC7 Development Server started at Fri Feb 26 18:49:29 2012 Listening on 127.0.0.1:8080 Document root is /home/ec2-user Press Ctrl-C to quit.
And now you can see the contents provided by the built-in web server:

Each client request will be written to the console:
80.180.55.37:36318 : / 80.180.55.37:36584 : /
Going back, let's look at the "-S" command line parameter, which is used to specify the address from which the server will be accessible. Possible values:
localhost - the server will be accessible only from the local machine,
0.0.0.0 - on any machine interface,
Any external or gray IP - only on the specified IP
The "-t" option sets the specified directory to "directory root". For example:
$ php -S :8090 -t /home/ec2-user/public
Besides,. you can specify the name of a specific router file. For example:
$ php -S >localhost or your public IP>:8080 -t /home/ec2-user/public public/index.php
The output of this router will be parsed and executed by the server. Simple example: