“Ficus” here is that “global variables” should not be chosen randomly, as you do, but use only those that are suitable for a particular task.
Theoretically, HTTP_HOST and SERVER_NAME can be used for INCLUD, but I very much doubt that a folder with the name of the server was created in the root of the website on the disk. Most likely, you just confuse, like all beginners, a file on a disk and an HTTP resource on the server. Here is a good article that explains the difference .
Most likely you need DOCUMENT_ROOT , but first you have to decide which way you need it , and then try to build it with variables.
If we analyze these examples in detail, then let's assume that our site is located in /home/www/example.com/htdocs . Then the first two examples will lead to
/home/www/example.com/htdocs/Soft/example.com/connection.php
while should lead in
/home/www/example.com/htdocs/connection.php
at the same time, in DOCUMENT_ROOT, on the correctly configured server, the path you need should be located /home/www/example.com/htdocs - and that’s what you need to substitute in the inclusive.
And the third example is incorrect from the syntactic point of view. If you write inside double quotes, you can do this:
include_once("$_SERVER[DOCUMENT_ROOT]/connection.php"); include_once("{$_SERVER['DOCUMENT_ROOT']}/connection.php");
but I would prefer the option through the dot.
connection.phpfile really found in the$_SERVER['HTTP_HOST']or$_SERVER['SERVER_NAME']relative to the current path? - user6550print "http://".$_SERVER['SERVER_NAME'];showshttp://www.site_name.ru? - I_CaR$_SERVER['SERVER_NAME']variable contains the value ofwww.site_name.ru. Consequently, the constructs expand toinclude_once("www.site_name.ru/connection.php"). And in the file system there is simply no such path relative to the directory from which the invocations are called. - user6550