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

Problems with the Linux version of XAMPP, questions, comments, and anything related.

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

Postby session13 » 20. May 2010 10:34

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.
Last edited by session13 on 21. June 2010 10:49, edited 1 time in total.
session13
 
Posts: 4
Joined: 20. May 2010 08:15

Solution

Postby session13 » 20. May 2010 12:01

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.
session13
 
Posts: 4
Joined: 20. May 2010 08:15

Again the same problem

Postby session13 » 21. May 2010 08:18

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?
session13
 
Posts: 4
Joined: 20. May 2010 08:15

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

Postby peterson » 21. June 2010 08:36

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.
peterson
 
Posts: 4
Joined: 21. June 2010 07:46

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

Postby session13 » 21. June 2010 10:49

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.
session13
 
Posts: 4
Joined: 20. May 2010 08:15


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 13 guests