PHP Include Not Working

software development


I’m just learning php and trying to set up a php form. I’ve got my form working on a .php file but I want to have an html file use an include to pull the form from the .php file. For some reason I can’t get my include to do anything. (It’s probably a glaringly obvious mistake.)

When I load the below html page it does not include the form from the include, just the header text, everything else is blank.

visit the page to see what I mean -
and check out the php here -

Any Help please?

Here’s my code (it’s very short):

The HTML page:

<?php include 'DHform.php'; ?>


The DHform.php Code:


<?php include('DHform.php'); ?>


You need parentheses to call functions. Also make sure that the include script is in the same directory as the script that is trying to include it (since you don’t specify a path).


In addition to what OSHA correctly points out, Apache on Dreamhost is not set to parse PHP code in .html files by default. If you want it to do so, you can create an .htaccess file and include the appropriate handler, like so:

AddHandler php-cgi .html .htm .php



You can’t do this.* HTML files are just HTML files, they’re not scripts or anything, and they will not run PHP code. If you want something to process the include, then you need to put it into a PHP file.

Try renaming your files something like:
DHform.html -> DHform.php
DHform.php ->
and then make the necessary changes to your include statement to match the new filenames.

  • Well, you can, if you map .html to be run by the PHP handler. But there’s no real reason to do this.

Technically, include is a built-in, not a function. It’ll run without parentheses just fine.


I agree completely - your answer was "mo’ bettah’ than mine. :wink:



Thanks so much for everyones response. I changed the .html to a .php and it works perfectly fine. (I knew it was something simple.)

Here is the reason why I wanted to use an include in .html. I use Wordpress for my whole already built site and it would be easier for me to be able to simply insert an include in the already made html pages and not have to adjust all the links to the page when I give it a new .php extension.

What would be the cons to creating an access page that parses the .html as php? Doesn’t parsing it as php simply add more functionality than as html?


Well, it does “add more functionality” in that you can include php code in your html, but it places an unnecessary processing overhead on the server to parse all your .html files just go be able to handle those that have php code in them.

I think it is better to just use PHP files. The WordPress issue may be a lot less relevant than you are assuming, because WordPress uses PHP files for all it’s processing anyway. With the proper plugin, you can already embedd PHP code in WordPress posts without any need for a handler. :wink:



Well, the main reasons for not converting .html to interpret as PHP are twofold. First, programmers don’t expect .html files to be run through any sort of script processor. If someone else is ever working on your site, they might come across this behavior unexpectedly, with some potentially bad consequences. Second, since .html files are static, they can be served up very quickly and easily by Apache. It takes a lot more overhead to run the PHP interpreter on a file than it is to simply throw the file down the pipe.

These reasons are augmented by the fact that there are other ways to achieve the same results on the user side. Apache’s mod_rewrite will let you map any .html file request to a .php script in a way that’s completely transparent to the user.

Also, you mention Wordpress. Are these .html pages cached posts that Wordpress automatically generates? If so, I think you can tell Wordpress to regenerate these pages when you change your link structure, so you shouldn’t be losing too much. But, I may be wrong on this one, since I’ve never had a blog busy enough to warrant using a static cache, and have therefore never tried it myself.