Page 1 of 1

[Solved] PHP include() function doesn't work in .html files

PostPosted: 20. May 2010 10:34
by session13
Hello,

I have Ubuntu 9.10 and LAMPP 1.7.3a. There is no problem running .php sites like phpBB3 but when I include some file, e.g.
Code: Select all
<?php include("included.html"); ?>
into .html file (e.g. index.html) then the included.html file doesn't seems to be included when I'm looking at the page in a web browser.

The problem doesn't exist when the same files (index.html and included.html) are uploaded to a web hosting company server.

I would appreciate any help.

Solution

PostPosted: 20. May 2010 12:01
by session13
I've found some solution.

According to http://forums.digitalpoint.com/showthre ... ost7129274 I've added
Code: Select all
<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>
to .htaccess in the site folder and now include() function works.

Again the same problem

PostPosted: 21. May 2010 08:18
by session13
After system restart, again php don't parse my html documents. Also .htaccess is ignored by Apache (inserted gibberish and there was no error) and I'm not sure does it ever read it before. In httpd.conf all directives AllowOverride are set to All.

Any ideas?

Re: PHP include() function doesn't work in .html files

PostPosted: 21. June 2010 08:36
by peterson
If you want the "include" function to work correctly with paths and GET parameters, try the following code:

<?php
$_GET['param1'] = 'param1value';
$_GET['param2'] = 'param2value';
@include($_SERVER['DOCUMENT_ROOT'] . "/path1/path2/include.php");
?>

Then within your "include.php" use $_GET['param1'] and $_GET['param2'] to access values of parameters.

Re: PHP include() function doesn't work in .html files

PostPosted: 21. June 2010 10:49
by session13
Thanks for your reply

I'm not really skilled in php yet so I didn't understand much from you post. Only what I wanted was simply to include html file into another html file. I knew that I must make Apache parse html files for php code using something like AddType application/x-httpd-php .php .html .htm to .htaccess file. Because this file was not parsed by Apache (and I can't make it happen), I added above line to the end of /etc/apache/apache2.conf (I've deleted XAMPP and installed Apache from deb package).
After reload (/etc/init.d/apache2 reload) php parser started including the html file.