Include() failed opening

What I’m trying to do is pretty simple, but it’s giving me a huge headache. What I want to do is include my header.php and footer.php files on the .html pages on a website. I tried:

<?php include("header.php"); ?>

and that would work on my localhost (apache2 server), however it wouldn’t work when I uploaded to DH.

So I tried

<?php include(""); ?>

After doing some research and this won’t work either. Am I heading in the rigth direction? Am I even able to edit any php settings on the DH server? Any help is greatly appreciated at this point!

<?php include(""); ?>


With includes you have to use your absolute path. Using won’t work. It has to be more like:

If your header is in the same directory as your index page, then you are almost correct. Use single quotes not double. You need to tell php that the period in your file name is literal.

I’ll give it a shot! Thanks for the quick input guys. DH is down for me apparantly, I can’t load the website in a browser, and my FTP won’t connect soooo… I’ll give it a shot and give an update when it comes back up! Thanks again! =)

Well I made the change to single 's and uploaded the test .html file, and the header.php nor footer.php displayed… =(

I did find this after loading phpinfo() in include_path:


Do i need that dir on the server? Because judging from SmartFTP it doesn’t exist…

If all else is as detailed in the previous responders’ posts (either header.php is in same file as the “including” file, or the full server path - not url- in addition to the ‘header.php’ is inside the single quotes) the problem is likely to be that php is not parsing your includingfilename .html file.

The including file should be a .php file for the standard Dreamhost configuration to recognize it as PHP and parse it.

[quote]I did find this after loading phpinfo() in include_path:


Do i need that dir on the server? Because judging from SmartFTP it doesn’t exist…[/quote]
You are trying to make it harder than it is. SmartFtp won’t show that fidirectory in your directory, because it is “above” your directory on the server’s directory Tree. Additionally, that directory is not one you can write to (you don’t have adequate permissions, as it is used by all users on your server). The term “include” means it is the path where system-wide includes are searched, if no other location is defined. When “including” your own files within your own directories, you don’t put them there (you can’t), rather you put them somehwhere in your directory space, and reference them as previously described.


That did it! Wow thanks a ton! I had no idea i needed to name my .html files .php. Is this standard practice? I mean, I’d rather have them as .htmls - what can I do to get around this, if anything?

Yes it is a standard practice. ‘.html’ is used for HTML documents with just HTML. ‘.shtml’ is used for HTML documents with server-side includes. And ‘.php’ is used for PHP files. This is because the Apache web server uses the filename extension to determine what action is associated with the file.

The web server documentation is available at where you can learn how the web server works and what things you can configure using .htaccess files.

The DreamHost Wiki has a related question and answer at:
What extension should my php files have?

:cool: [color=#6600CC]Atropos[/color] |

Yes, it is and unless you have a compelling reason not to adhere to that practice I strongly recommend that you name PHP files .php (or, actually anything but .html!) Older php programs used to be named .php3, to distinguish them from PHP4 programs, but that created more than enough confusion for new programmers.

Please do not take this as being condscending or disrespectful of your knowledge, but the kinds of things you can do to have .html files parsed as PHP by PHP, seem to me to be a little advanced for you, given that you were not aware that the parser for PHP operates on .php files. There are ways to do this, and it is not hard to set it up, using .htaccess directives, but I submit you will be opening yourself up to the very real possiblility of major confusion if you attempt to operate that way before you have a better understanding of what’s happening.

If you really want to persue that, please become familiar with all the ramifications of doing so, and research the proper way to do it. See this link , and look near the bottom of the page for “How can I use ssi on files with .html extensions?”, for the general idea, then research how that would apply if you substitute php for ssi - same concept, you define a custom handler.

You can also search this forum, or the web in general, for more information on that - I’d really just rather not encourage you to do that until you fully understand it, as it could considerably complicate your learning. It is hard enough for experienced php programmers to keep straight, at times, what is being parsed as php and what is parsed as html within a single .php file. Preparing pages and finding errors when “everything is parsed as php”, even in an .html file, requires a very methodical process and is not advised while learning PHP. When the time comes where you can identify a reason to do it, you will probably have learned enough PHP to know how it’s done :wink:

edit: While I was posting this, Atropos7 pointed you to the specifics, which really was a much more direct answer to your last question. I was just trying caution you - what Atropos7 wrote is right on the money!


No disrespect taken at all. I simply wanted a way to be able to use headers and footers on my mom’s website so that I wouldn’t have to go change EVERY FILE whenever I changed a .css file or whatnot. I am VERY novice in the php world, and I can tell things are pretty complicated. If it is standard practice to leave all the webpages as .php, then I have no problem with that. Thank you for the resource link, and most of all, thank you for your time and help! This will make updating / changing content much easier!

Atropos, thank you for the wiki! I configured my .htaccess file and put it in my root directory, now the <?php include('header.php'); ?> is working, even my files with .html extensions! You guys have been a ton of help!

So now that both are working, which extension would YOU use for the webpages if it werent’ a very complex site, and you were using the php only for header and footer includes? .php or .html?

Good Deal! And you are on the “right” track by implementing such a “labor saving” footer/header process. I personally think you will be well served by that exercise in PHP, vice using ssi (which would serve a similar function), as you will gain some PHP knowledge in the process.

After you complete that excercise (and the “fun” of coding the HTML/PHP for you Mom’s site,and re-coding whenever she needs new content!) wears off, you might want to try the Dreamhost “one-click” install of Joomla Content Management System, which will give you plently of opportunity to learn PHP and HTML as you customize it, but will give your Mom the instant ability to add, delete, change content at will without your constant involvement.


That would serve to be very useful for the small updates such as “changing pictures”, etc. Maybe when I’m “up to snuff” in php I’ll incorporate something of that nature. I’ll do some research on that and look into it, thanks again!