Php includes. please help

software development



say for instance i have a page saved in one of my subdirectories.

example: “(”

how would i enter the php include code on that page because it doesnt work the same as it does for the pages in my main directory.

for the pages that i have saved in the main directory, example(, all i have to do is use this code:


because my includes are also saved in a subdirectory. but that code doesnt work for the pages in subdirectories so how am i supposed to write the include for the subdirectory pages?

hopefully im making sense!


I am no PHP expert, but I don’t see why the line above isn’t working for you.

$_SERVER[‘DOCUMENT_ROOT’] should return ‘/home/username/’, so your complete include path would be ‘/home/username/’, which should work regardless of which sub-directory the page with the include is located in.

In-fact, I just created a simple test on one of my domains. I created a small php file, /goodies/test.php, which contained the following;

[color=#0000CC]<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/header.php'); ?>[/color]

I browsed to this file and it included the /includes/header.php file with no problems.


Save [color=#CC0000]$50[/color] on DreamHost plans using [color=#CC0000]PRICESLASH[/color] promo code (Click for DreamHost promo code details)


Maybe the problems is with using short tags, are you also using xml?

My website


original poster: you don’t need to reference the absolute path when you are defining an include; you can simply reference the file you wish to include relative to the file that is calling it.

For example, if you want to include in, you could write (in the first lines of main.php):

require("../includes/functions.php"); Please keep in mind that you may need to include the files before any output is sent. This is sometimes necessary, depending on what the included file is supposed to do (i.e. start a session).

If this doesn’t work, let me know.



Try this code or use the relative paths that were shown to you before.

<?php include(''.$_SERVER['DOCUMENT_ROOT'].'/includes/header.php'); ?>

Use CLOPEZ as your promo code and get a fairly $50 discount (on most yearly plans)…or click here.