Forum Moderators: phranque

Message Too Old, No Replies

Attempting to parse .htm files with php includes and having trouble

parsing htm files with php includes

         

bowltrain

5:14 am on Jan 24, 2008 (gmt 0)

10+ Year Member



I have a multi-part question that I'm not sure where to post. Hopefully this spot will do.

I am switching my left hand nav bar to show up as a php include to simplify site updates and would like to keep the .htm extensions. I use Front Page to create and maintain my web and then FTP my files to the server. No Frontpage extensions. I would rename my files to .php but FP loses alot of functionality when dealing with .php files.

My .htaccess file begins like this:
---------------------------------------------------------------------------------

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<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.example.com
AuthUserFile /var/chroot/home/content/b/o/w/bowltrain/html/_vti_pvt/service.pwd
AuthGroupFile /var/chroot/home/content/b/o/w/bowltrain/html/_vti_pvt/service.grp

----------------------------------------------------------------------------------

I have tried adding the following statements to the bottom of my .htaccess with the results listed.

A.
AddType application/x-httpd-php .htm .html

Does not parse php in my test.htm file
correctly displays my test.php file
goes to a download screen when I access my main page (index.html)

B.
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Does not parse php in my test.htm file
correctly displays my test.php file
goes to a download screen when I access my main page (index.html)
(same as above)

C.
AddType x-httpd-php .php .htm .html
AddHandler application/x-httpd-php .php .htm .html

Does not parse php in my test.htm file
goes to a download screen when I load test.php
goes to a download screen when I access my main page (index.html)

D.
RemoveHandler .html .htm
AddHandler application/x-httpd-php .php .htm .html

Does not parse php in my test.htm file
goes to a download screen when I load test.php
goes to a download screen when I access my main page (index.html)

-----------------------------------------------------------------------------------

I am currently with Godaddy hosting on a shared server plan and cannot access the server .conf files or settings. This presents several questions:

a. Should I switch hosting companies? Godaddy has left a bad taste in my mouth. Is Godaddy ok? Is anyone else any different?
b. Should I switch to a virtual server so I can access the .conf files?

To sum up, my three questions are these:

1. Can anyone tell me what I need to do, with my current host, to get .htm files to parse as .php?
2. Do I need to upgrade to virtual hosting to do what I want?
3. If I decide to upgrade to virtual hosting, should I find a new company or is Godaddy ok?

If your still reading this, I thank you now for the time you've invested in my problem. Any more time you spend giving a response will be even more greatly appreciated.

[edited by: eelixduppy at 7:07 am (utc) on Jan. 24, 2008]
[edit reason] example.com [/edit]

Habtom

5:53 am on Jan 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try the following:

AddHandler application/x-httpd.php .php .htm

bowltrain

7:14 am on Jan 24, 2008 (gmt 0)

10+ Year Member



Thank you. But that did not do it.

The pages behaved the same as with no .htaccess entry

Marcia

7:47 am on Jan 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use Front Page to create and maintain my web and then FTP my files to the server. No Frontpage extensions.

Then why do you have all this Front Page stuff in .htaccess?

My .htaccess file begins like this:

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<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.example.com
AuthUserFile /var/chroot/home/content/b/o/w/bowltrain/html/_vti_pvt/service.pwd
AuthGroupFile /var/chroot/home/content/b/o/w/bowltrain/html/_vti_pvt/service.grp


That's all FP stuff, and FP is notorious for not playing well at all with .htaccess

bowltrain

8:04 am on Jan 24, 2008 (gmt 0)

10+ Year Member



Thanks for pointing out what those entries were from. I had been using the FP extensions to manage the site but switched over to a Linux machine and quit using the extensions at that time.

I had wondered what those entries were for.

I deleted them and retried the four entries from above, still with no luck.

I suspect my problem is in the httpd.conf file settings. But since I'm on a shared server I don't have access to that file.

Can I override those settings by placing a file in my folder, similar to doing that with .htaccess?

Or do I need to bite the bullet and move to a virtual server so I can access that file?

Or is there another way out?

Marcia

9:07 am on Jan 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bowltrain, write support at your host and ask about whether you've got .htaccess enabled, and if you've stopped using FP Extensions altogether, you really don't need to have them enabled by the host for your account.

You really don't need your own server to manage unless it's otherwise warranted; plenty of people parse .html files for php with shared hosted, though how it's done exactly can vary from one host to another depending on their configuration.

This is what's working for me now, with one hosting account:

AddHandler application/x-httpd-php .html .php .htm

But it's working with something different at another host.

Best thing: check with the host about disabling FP extensions for the site (it's enabled when the site is set up) and also ask them how to do the html/php thing on their system. If tech support doesn't know, ask them to escalate it to 2nd level support.

jdMorgan

4:01 pm on Jan 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The PHP authors used a kludge when 'hooking up' the original PHP implementation to Apache.

For example, the code posted above by Marcia is totally invalid -- But it often works!

Do not confuse the AddHandler and AddType directives like the PHP authors did -- Look them up in the Apache mod_mime documentation [httpd.apache.org] -- They are completely different, and require different parameters.

AddType declares a MIME-type, so that Apache can send the Content-Type response header to the client. It takes a MIME-type and one or more file extensions as arguments:


AddType text/html .php

AddHandler tells the server what to do with specific filetypes. It takes a 'disposition' and one or more filetypes as arguments. The usual two choices for disposition are "send them to the client" or "parse them for executable scripts."

AddHandler server-parsed .php

Those two directives together *should* work on any Apache server. But because of the kludged-up API hook mentioned above, they often don't.

So either experiment with this and other suggestions, or ask your host as suggested above.

Jim

bowltrain

5:53 am on Jan 25, 2008 (gmt 0)

10+ Year Member



Thank you both for your input. Unfortunately, I'm still not having any luck getting an .htm file to parse as .php.

JDMorgan
If I'm understanding correctly neither code example you gave should work.

--------------------------
the "AddType text/html .php" seems to add a .php file to the "text/html" mime type

is that line of thinking correct?

--------------------------

"AddHandler server-parsed .php" seems to tell the server to parse files with the ext of .php

how about that one? is line of thinking B correct?

---------------------------

I've spoken with Godaddy tech support with no luck. I've opened an account with another hosting company with a slightly different setup that let's me see stuff I couldn't see at the Godaddy,(am I ok mentioning these hosts? not trying to spam or defam)

I've spoken with the new host's tech support with no success as of yet.

robsoles

12:55 pm on Jan 25, 2008 (gmt 0)

10+ Year Member



Hey Guys,

I think that

AddType text/hmtl .php

tells Apache to put 'text/html' in the header for clients as the content-type value and

AddHandler server-parsed .php

tells Apache to parse as server side script files marked .php, if I am right then you probably want a bit of a combination of 'B' & 'C' with the addition of small change to something Jim gave us:

RemoveHandler .html .htm
AddHandler server-parsed .htm .html
AddType x-httpd-php .php .htm .html
AddHandler application/x-httpd-php .php .htm .html

and you may or may not need to put '.php' on simile of next line because that should be in the httpd.conf file - don't be shy and correct me...

AddHandler application/x-httpd-php .php .htm .html

I hope that helps,
robsoles.

jdMorgan

1:08 pm on Jan 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Response to bowltrain's post above:
No, both lines I posted above are correct "by the book" for Apache. Files with a .php extension should (almost always) be server-parsed, and the html/php script output should always be sent to the client as text/html (unless it's an XHTML+XML site).

But you're wanting to also parse html files for embedded php code, and so "by the book" would want to add .html to the AddHandler filetype string.

Unfortunately, as I said above, PHP did not go "by the book" in interfacing to the Apache API, and your problems are the legacy of that mistake/decision. Since your problem is equal parts Apache and PHP and is a very common one, I'd also suggest you investigate some of the threads in our PHP forum turned up by this search [google.com] in addition to those you've read in this forum.

Jim

[edit] Clarify confusion from cross-posting. [/edit]

[edited by: jdMorgan at 1:20 pm (utc) on Jan. 25, 2008]

Marcia

9:28 pm on Jan 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is the problem I had a few days ago with php includes on HTML pages; all of a sudden HTML pages that had always worked were giving a warning about downloading files:

[webmasterworld.com...]

I tried all different combinations and different code and finally got it to stop happening by using the above, but at first was concerned that the site got hacked and was serving malware.

coopster

11:20 pm on Jan 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Another discussion on the subject at WebmasterWorld. Well worth your time to read and understand:
[webmasterworld.com...]

bowltrain

7:09 pm on Jan 28, 2008 (gmt 0)

10+ Year Member



Thank you to everyone who provided feedback and insight.

I was unfortunately unable to resolve this issue and have decided for the time being to use ssi and .shtml file ext.

I have had some other considerations present themselves and so will likely move to a virtual server where I have more control.

Thanks again for your input.

bowltrain

g1smd

1:18 am on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I had this problem last week, and this is what worked for me:

# Allow .html extension URLs to be PHP scripted files:

AddType application/x-httpd-php .html