3

I have a file.php located in www.example.com/folder/.

I want that file to use include command for files located in www.example.com/include/.

If I simply use:

<?php include './include/footer.php';?>

It doesn't work, as it will try to search in the physical folder where the file.php is located, while I need it to refer to the root of my domain.

rockyraw
  • 1,125
  • 2
  • 15
  • 36

1 Answers1

8

Use $_SERVER['DOCUMENT_ROOT']

Here's the server documentation.

The document root directory under which the current script is executing, as defined in the server's configuration file.

Together, it should look like this:

include $_SERVER['DOCUMENT_ROOT'] . "/include/footer.php";
A Friend
  • 1,420
  • 17
  • 22
Chin Leung
  • 14,621
  • 3
  • 34
  • 58