Here's the problem:

Like most, I'm developing on an office network server, "localhost", and migrating pages to a live server on the


I have several layers of folders with pages that refer back to "localhost/incudes" and "localhost/images" for

example using "../../../includes/key.php" for example.

I have coded the following to try to connect to the desired folders for 'include' operations, but it doesn't

work and I don't know why.

Here is the code that heads the pages I am working on.

$srclocation = $_SERVER['SERVER_NAME']."/includes/key.php";
echo $srclocation;
include ($srclocation);

The variable '$srclocation' looks correct in the echo command but I must be missing something.

The error messages on the pages read as follows:

Warning: include(localhost/includes/key.php): failed to open stream: No such file or directory in C:\xampp

\htdocs\lev1\lev2\lev3\page.html on line 6

Warning: include(): Failed opening 'localhost/includes/key.php' for inclusion (include_path='.;C:\xampp\htdocs

\includes') in C:\xampp\htdocs\lev1\lev2\lev3\page.html on line 6

It would be nice to make this work as it looks like it would simplify migrating pages to the live web site.

Thanks for any help and information

Recommended Answers

Change this line:

$srclocation = $_SERVER['SERVER_NAME']."/includes/key.php";


$srclocation = $_SERVER['DOCUMENT_ROOT']."/includes/key.php";

SERVER_NAME will return the domain name, not the path.

Jump to Post

All 3 Replies

Change this line:

$srclocation = $_SERVER['SERVER_NAME']."/includes/key.php";


$srclocation = $_SERVER['DOCUMENT_ROOT']."/includes/key.php";

SERVER_NAME will return the domain name, not the path.

what he said ^^

relative path statements will remain correct
will always be up3 down folder and access file
relative links will work if the system is not installed at the root of the live server (or moved later)
or use a config that sets a full basepath at install, and is included in all other files with a well document edit point

being that web-devs are probably operating with an incomplete specification, expected to produce a perfect rendition of what senior somebody keeps changing every second day

how hard will the browndraft hit when senior management decides they want it relocated, and developers havent left a simple path for the change (that the spec they are working off doesnt include)

noun;perjorative, brown-downdraft. the effect where senior people sh_t on their immediate subordinate and the sh_t ball develops increasing momentum as it rolls down, each layer of seniority adding their own sh_t onto their ,subordinate till it finds someone that all the above agree is responsible

adjective;. imaginary status assumend by people who have risen in a hierachy to the point that their ill-considered decisions can be corrected completely by lower ranks without their notice, allowing them to take credit without doing anything

1;noun, lowest layer in a browndraft
2;noun, one who as been able for so long, to produce so much, from so little, that they have become able to produce anything from nothing
see also miracle worker,

The '$srclocation = $_SERVER['DOCUMENT_ROOT']."/includes/key.php";' works on the local dev. server and I will try it on the 'Live' server as soon as I can.

Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.