Using include file - directory structure

Hi,
I have made a website for my son and while everything works okay, he wishes to change hosting company.

Having uploaded the site to the new host there is a problem with it finding the include files

The current site is http://www.dalrenmodels.co.uk/ and this works fine

He has set a tempory space on the new host so we can test the site before changing the name servers

That new space is http://www.dalrenmodels.co.uk.gridhosted.co.uk/ but this is where we are having the problem although all the code is identical ( I have simply uploaded all the existing files to the new space)

In the code there is reference to two include files, menu.php and footer.php. I need to keep these file separate otherwise I would have to change the code in every page if I update the menu or footer.

The code in question in my index.php files is:

<?php
include $_SERVER[‘DOCUMENT_ROOT’] . ‘/includes/menu.php’;
?>

Plus similar for the footer.

To make the home page work on the new hosting I have to prefix the include command with a single dot, just before the first slash, thus:

include $_SERVER[‘DOCUMENT_ROOT’] . ‘./includes/menu.php’;

However, this still does not fix the other pages.

There are model category pages (accessed from the footer) and to make these pages work I have to prefix the command with two dots, thus:

include $_SERVER[‘DOCUMENT_ROOT’] . ‘…/includes/menu.php’;

This then breaks the home page and the individual model pages still don’t work. To make them work I have to prefix the command with two dots, a slash and two dots, thus:

include $_SERVER[‘DOCUMENT_ROOT’] . ‘…/…/includes/menu.php’;

But this then breaks everything else.

I hope I haven’t rattled on too long and someone can explain what is going on and how I can fix it.

Thank you in advance for any help you can give,

regards

Brian

I have temporarily fixed the problem by using an absolute path, but that means I can’t test the site properly at home.

A simple solution would be to set a constant with the absolute path of the includes folder.

define(‘INCLUDES’, ‘/home/account/public_html/includes/’);

include INCLUDES . ‘menu.php’;

Something like that.

You are on the right path, first remove $_SERVER[‘DOCUMENT_ROOT’] then use this.

include ‘./includes/menu.php’;
include ‘./…/includes/menu.php’;

The ./ actually means start the search from the file from this directory.

Assuming that none of the files are included from multiple directory levels you can do this (either by mod_rewrite or by files including files etc.).

If you have a problem with that use:

include DIR.‘/includes/menu.php’;