0

I want to include a .php file, containing a menu bar, in all my pages. Thing is, some of these pages are at different levels: for example, on might be in the root directory, another might be in root/news, another in root/news/2012, and so on. What can I do to make this include always link back to the menu bar file, which is located in my root directory?

2
Contributors
9
Replies
11
Views
5 Years
Discussion Span
Last Post by glycerine
1

You could do something like

include('path/to/file/header.php'); //path/to/file being full path name 
0

But to make a link always point to a file in the root folder, don't I have to add something along the lines of ../menubar.php or ./menubar.php?

1

no you can use

include('http//yourdomain.com/header.php');

Edited by glycerine

0

I see...
I'm new to PHP. In your second example, is "DOCUMENT_ROOT"supposed to be replaced by the path to the root, or does it just state that the next path is root-relative?

0

I get this:

Warning: include() [function.include]: URL file-access is disabled in the server configuration

1

ok you need to set the absolute path now this depends how you webserv is setup.
add this to you header.php (menu bar file)

echo $_SERVER['DOCUMENT_ROOT'];

this will give the full path to header.php file then use this instead of http://www.yourdomain.com

so it should look something like

include('var\www\header.php');
0

That seems to work perfectly; however, just before trying this, I tried ./menubar.php, which also worked; although, that's probably not an absolute path. Thanks!

0

Yes using ./ will work but if you go deeper it started to get messy. eg ../../../../header.php

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.