Help - Search - Members - Calendar
Full Version: PHP includes
Movable Type Community Forum > Additional Resources > Tips and Tricks
davidham
Hello,

This is probably a dumb config error of some kind, but when I try to do a PHP include of my site's header, I get this error:

Warning: Failed opening '/includes/displayheader.php' for inclusion (include_path='.:/usr/lib/php') in /Library/WebServer/Documents/index.php on line 28

line 28 is the include and reads:

include ("/includes/displayheader.php");

(within php tags which the board seems not to like)

Did I do something wrong? Is there a config setting I need to do somewhere? Thanks a million for any help you can offer,

OK
DAH
kadyellebee
You might double check with your host -- some versions of PHP may require the full path. For example, my includes are in this format:
CODE
<? include("/home/USERNAME/public_html/DIRECTORY/header.php"); ?>

smile.gif
Kristine
davidham
Kristine,

Thanks! I put in the machine root for the include path, and it worked fine.

Two things:
Is there any way to avoid putting in the whole machine root? is there a PHP setting I can do that will add the document root to my include_path?

Also, the include has some MT code in it, and when I view the page, the MT code appears in the browser. Does this mean I have to publish the included file as an MT template?

Thanks again for your help,

David Ham
jayseae
If by "MT code", you mean MT tags, such as MTEntries or something, then it will need to be rebuilt through the MT build system. Otherwise there will never be an occasion when the tags are parsed to return the appropriate value.

I've got my header set up as an index template that builds a file (say header.php), and then in other templates, I use PHP to include that file - but that file goes through the MT build process.
stepan
QUOTE (davidham @ Sep 24 2003, 07:27 PM)
Is there any way to avoid putting in the whole machine root?  is there a PHP setting I can do that will add the document root to my include_path?

If you specify a relative path (i.e. one that does not begin with "/") then PHP will try to include it realtive the the includer's directory or relative to one of the paths in PHP's include_path setting. Look at php.net for more info.

The easiest way to do this is to specify a path relative to the file that's being built, i.e.:
CODE
<? include("DIRECTORY/header.php"); ?>
or, if the built file is in a higher directory (for example 'archives'):
CODE
<? include("../DIRECTORY/header.php"); ?>
davidham
Stepan,

I just saw this today, but thanks very much, I'll try it right out.

This support forum RULES, thanks again everyone.

OK
DAH
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.