Here's the problem:

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

web.

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.

<?php
error_reporting(E_ERROR|E_WARNING);
session_start();
$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:

localhost/includes/key.php
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

Dougsix@earthlink.net

Recommended Answers

All 3 Replies

Change this line:

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

With:

$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
../../../folder/file
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)

browndraft:
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

senior:
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

developer:
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,

Thanks,
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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.