Forum Moderators: phranque

Message Too Old, No Replies

parsing .htm pages with php

I want to use php in .htm pages

         

j_a_c_k

9:37 am on Nov 7, 2005 (gmt 0)

10+ Year Member



I want to parse .htm pages with php. I have reviewed several threads here and have been unable to make it work.

Part of my trouble may be that I am using MS FrontPage which puts some of its own stuff into the .htaccess and it has been quite some time since I undertook to understand just how FP uses .htaccess.

Here is my test page code.
=================
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
Hi Mom&nbsp;
<p>
<?php
phpinfo();
?>
</p>
<p>Hi Dad</p>
<p>&nbsp;</p>
</body>
</html>
=====================
First I tried changing my httpd.conf by adding .htm to the AddType code:
=================
<IfModule mod_php4.c>
AddType application/x-httpd-php .php .php4 .php3 .phtml
AddType application/x-httpd-php-source .phps

==Like this ================
<IfModule mod_php4.c>
AddType application/x-httpd-php .php .php4 .php3 .phtml .htm
AddType application/x-httpd-php-source .phps

===================
The result is that, if and only if the .htm page contains php code, instead of parsing the php code. The entire page is downloaded to a temporary file and the temporary file opens in a new window as html, ignoring the php as comments.

I took the code out of the httpd.conf file and put it into the .htaccess
AddType application/x-httpd-php .htm
with exactly the same result, the page downloads and opens in a new window as html ignoring the php as a comment.

For reference, here is my .htaccess file:
======================
# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*
AddType application/x-httpd-php .htm

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.myservername.com
AuthUserFile /var/www/html/_vti_pvt/service.pwd
AuthGroupFile /var/www/html/_vti_pvt/service.grp
===========================
Let me say also that pages named .php work just fine as do those named .htm which contain no php code.

As it is 05:00 hours, I am going to bed, with hope that someone will point out my error.

jdMorgan

1:52 pm on Nov 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



j_a_c_k,

Welcome to WebmasterWorld!

It looks to me as if you've got AddType [httpd.apache.org] and AddHandler [httpd.apache.org] confused.

Rather than declaring that the MIME-type of your htm files should be application/x-http-php by using AddType, you'd be better off telling the server to parse htm files for php includes using AddHandler:


AddHandler server-parsed .htm

You can verify that the server responds with appropriate MIME-types for each requested resource type on your site by using the Server Headers checker [webmasterworld.com].

Also, using .htaccess with FrontPage extensions [webmasterworld.com] causes a major headache, in that you will probably have to hunt down every .htaccess file in every FrontPage extension-related directory on your site, and change Options None to Options +FollowSymLinks in each of those .htaccess files whenever you "publish" a new version of the site.

Jim

j_a_c_k

3:48 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



Thanks Jim,
I recognize the problems with FrontPage. I really want to fix the problem in the conf files but cannot be restarting the server while its on-line.

Fixing this in .htaccess in a side directory is easier. Once that works, transferring the fix to conf is the second set of problems. Problems usually saved for late at night.

All that aside, I tried the
=========
AddHandler server-parsed .htm
=========
statement, the server did not parse the php but simply returned it as comments in the html.

Re-searching the forums, I have tried adding
=========
AddType text/html .htm
AddHandler server-parsed .htm
==========

And I have tried
===========
Options +Includes
AddType text/html .htm
AddHandler server-parsed .htm
===========

none of these had any effect.

I am confused by one thing here, how does the server know with what to parse this code, nothing here tells the server to look for php code as opposed to say ssl or perl?
My server runs php as a cgi, is that a problem?

jdMorgan

4:11 pm on Nov 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It can select the parser using the "<?" in the file -- Understand that it doesn't actually have to select a parser, it just lets them all take turns parsing the code and interpreting the commands they recognize.

Are you on Apache 1 or 2?

If on Apache 1.x, make sure that PHP appears *before* mod_rewrite in the LoadModule list. Modules are invoked in reverse order to that shown in the LoadModule list. Therefore, if PHP appears *after* mod_rewrite in the LoadModule list, it will run *before* any mod_rewrite code can be processed and have any effect.

Jim

j_a_c_k

5:27 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



I am running Apache/1.3.27
So I moved the
===========
LoadModule rewrite_module modules/mod_rewrite.so
===========
Statement to the end of the LoadModual List.

I also moved the
AddModule mod_rewrite.c
to the end of that list

Restarted the server with no effect.

j_a_c_k

8:01 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



Jim,

In reviewing this problem, I cleared all the changes that I have made.
I went back to the httpd.conf and made this one change to create a page type .zxz.
===============
<IfModule mod_php4.c>
AddType application/x-httpd-php .php .php4 .php3 .phtml .zxz
AddType application/x-httpd-php-source .phps
</IfModule>
=================
The test page renamed to test.zxz worked just fine.
This tells me that there is something inhibiting the parsing of .htm pages.

Any Ideas?

j_a_c_k

2:38 am on Nov 8, 2005 (gmt 0)

10+ Year Member



Problem Solved.
My fault was in NOT REMOVING .htm .html from the
server configuration statement:
===============
AddHandler server-parsed .shtml .html .htm
===============

Prior to adding .html .htm to the statement
===============
<IfModule mod_php4.c>
AddType application/x-httpd-php .php .php4 .php3 .phtml .htm .html
AddType application/x-httpd-php-source .phps
</IfModule>
================

This conflict apparently caused .htm & .html to be doubly assigned.