Are $ _SERVER ["SERVER_NAME"] and $ _SERVER ["DOCUMENT_ROOT"] always aimed at the same directory?

Do $_SERVER["SERVER_NAME"]; and $_SERVER["DOCUMENT_ROOT"]; are always resolved to the same directory? Is there a scenario where they will not?

EDIT:

To clarify, I KNOW that this is not the same thing - I am trying to establish only whether SERVER_NAME will always be displayed on DOCUMENT_ROOT. that is, following each of them, it will always be in the same physical place in the server file system.

0
source share
3 answers
  • SERVER_NAME - Internet access address - stackoverflow.com
  • DOCUMENT_ROOT - absolute URL of the current directory - in the server / data / stackoverflow / ...

but yes, it targets the same directory (every time)

+2
source

SERVER_NAME is not the way it should be the actual domain name. You can enable REQUEST_URI , which will give you an absolute path from the point of view of the web server (provided that you just use the files. REQUEST_URI provides you with the path entered by the user. The web server or PHP itself can deliver content that is not even in the file)

For this, it really depends on what in $some_relative_path

DOCUMENT_ROOT is the absolute path to the server where the files on your website really live on the server. DOCUMENT_ROOT may be useful for including other PHP files, but it should never be exposed to the connecting client, as this is a security risk.

They should never be the same in any scenario unless for some reason someone installs / on the server as the root of the document. This is likely to be a very bad idea, because then even system files will be available on the Internet.

+1
source

SERVER_NAME is the name of the server on which the script is running. It can also be a virtual host name.

DOCUMENT_ROOT is the path to the script you are running. If you use some kind of URL rewriting, it could be the same value as SERVER_NAME

0
source

Source: https://habr.com/ru/post/897491/


All Articles