Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 5th Jan 2010, 03:52 AM   #1
Advanced Warrior
War Room Member
 
Join Date: 2005
Location: , , .
Posts: 635
Thanks: 48
Thanked 86 Times in 55 Posts
Default
Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

What I want is for my .html files to be parsed as if they are .php

I have tried adding to the .htaccess :

AddHandler x-httpd-php .html .htm

and

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

and

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

The last one actually causes the browser to want me to open it with an application so I know that the .htaccess is being read.

I have also tried adding via the cpanel apache handler.

But it is not parsing it as .php.

So, for example if I use the code:

<?='hello'?>

It is showing as that in the source code.

Any help?

Thanks,

Ben Shaffer

BenShaffer is offline  
Unread 5th Jan 2010, 04:21 AM   #2
From IT to IM
War Room Member
 
Voon's Avatar
 
Join Date: 2009
Location: The World Is Flat
Posts: 37
Thanks: 36
Thanked 5 Times in 5 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

I use this in .htaccess

Code:
<FilesMatch ".(htm|html)$">
  SetHandler application/x-httpd-php
  ForceType application/x-httpd-php
</FilesMatch>
Originally Posted by BenShaffer View Post

<?='hello'?>
This would require 'short_open_tag' enabled in PHP.

.
Voon is offline  
The Following User Says Thank You to Voon For This Useful Post:
Unread 5th Jan 2010, 04:28 AM   #3
Advanced Warrior
War Room Member
 
Join Date: 2005
Location: , , .
Posts: 635
Thanks: 48
Thanked 86 Times in 55 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Thanks. Weirdly, this is causing the browser to ask how to open the file.

Any other suggestions?

Ben Shaffer

BenShaffer is offline  
Unread 5th Jan 2010, 06:08 AM   #4
HyperActive Warrior
War Room Member
 
Tim Brownlaw's Avatar
 
Join Date: 2009
Location: Berwick, Melbourne, Australia
Posts: 156
Thanks: 5
Thanked 47 Times in 28 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Ben - what hosting are you using?

I've given the same solutions as above in one of my installation guides for my dynamic link cloaking - as an aside and I've not actually tried it... naughty me!

So naturally I'm concerned as it appears it don't work on some hosting servers!

I scoured Google on this and there are others ( strangely enough ) experiencing the same problem you are seeing.

Some - and I'm only regurgitating what some folk reckon works - suggest the following.

Code:
AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php .php .htm .html
Disclaimer : This is untested (by me) and looks strange so it's only something to try...

I'd contact your hosting techs and see what light they can shed on this..

Let us know what you find! I'd certainly be interested.

Cheers
Tim

Great Success is built from many little successes!

http://www.timbrownlaw.com - My Wee Part of the World.

http://www.LookingOverMyShoulder.com
Tim Brownlaw is offline  
Unread 5th Jan 2010, 07:12 AM   #5
Advanced Warrior
War Room Member
 
Join Date: 2005
Location: , , .
Posts: 635
Thanks: 48
Thanked 86 Times in 55 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Hi Tim,

I just bought a site so am currently on their dedicated server with my own cpanel. Not really sure a lot more than that apart from the following pasted from cpanel:

Hosting packagestandardServer NamehostcPanel Version11.24.5-STABLEcPanel Build38506Themex3Apache version1.3.41 (Unix)PHP version5.2.6MySQL version5.0.85-community-
log Architecturei686Operating systemLinux
I tried what you said and it had the same problem - asking which app to open it with.

All I really want to do at this point is to use includes from the header and footer. Perhaps there is another way to do this without changing the file extension?

Ben Shaffer

BenShaffer is offline  
Unread 5th Jan 2010, 09:11 AM   #6
VIP Warrior
War Room Member
 
Join Date: 2006
Location: , , USA.
Posts: 1,795
Thanks: 70
Thanked 287 Times in 259 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Originally Posted by BenShaffer View Post

AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php .php .htm .html
It should be

Code:
AddType application/x-httpd-php .htm .html
AddHandler x-httpd-php .htm .html
Take out the ".php"
I don't think you need the AddHandler though. Try it without it.
KirkMcD is offline  
Unread 5th Jan 2010, 09:40 AM   #7
Advanced Warrior
War Room Member
 
Join Date: 2005
Location: , , .
Posts: 635
Thanks: 48
Thanked 86 Times in 55 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Kirk,

Forgive me if I am mistaken, but are you not just repeating what I said in my original thread?

B

BenShaffer is offline  
Unread 5th Jan 2010, 11:19 AM   #8
VIP Warrior
War Room Member
 
Ross Dalangin's Avatar
 
Join Date: 2005
Posts: 1,604
Thanks: 350
Thanked 214 Times in 161 Posts
Blog Entries: 33
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

For web servers using PHP as apache module:

Code:
AddType application/x-httpd-php .html .htm
For web servers running PHP as CGI:

Code:
AddHandler application/x-httpd-php .html .htm
So use only one of them.

You can also try

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*).htm$ $1.php [NC]
Or
Code:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+).htm$ http://yourdomain.com/$1.php [R,NC]
or
Code:
RewriteRule ^(.+).htm$ http://yourdomain.com/$1.php [R=302,NC]
or else make it worst
Code:
RewriteRule terms.html terms.php
Ross Dalangin is offline  
Unread 5th Jan 2010, 02:50 PM   #9
Active Warrior
War Room Member
 
Join Date: 2004
Location: Florida
Posts: 68
Thanks: 21
Thanked 20 Times in 16 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

If your host is running php version 5, you should try:
AddType application/x-httpd-php5 .html .htm
Ken Shorey is offline  
Unread 5th Jan 2010, 04:05 PM   #10
HyperActive Warrior
War Room Member
 
Tim Brownlaw's Avatar
 
Join Date: 2009
Location: Berwick, Melbourne, Australia
Posts: 156
Thanks: 5
Thanked 47 Times in 28 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Originally Posted by BenShaffer View Post

All I really want to do at this point is to use includes from the header and footer. Perhaps there is another way to do this without changing the file extension?
Ben, I found this very quickly and it should help you out with what you want to do.

I've had a very quick "Squiz" over this and it looks like the answer is in there..

WWW FAQs: How do I include one HTML file in another?

It would still be good if we can get your PHP issues sorted.

Cheers
Tim

Great Success is built from many little successes!

http://www.timbrownlaw.com - My Wee Part of the World.

http://www.LookingOverMyShoulder.com
Tim Brownlaw is offline  
Unread 5th Jan 2010, 05:42 PM   #11
Knowledge Seeker
War Room Member
 
mlangille's Avatar
 
Join Date: 2007
Location: Greenville , SC , USA.
Posts: 63
Thanks: 32
Thanked 20 Times in 15 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Hey Ben

Here's a software tool PhpActivator that will help you out.
"O Yeah" it's free PhpActivator


Michael
mlangille is offline  
Unread 6th Jan 2010, 05:10 AM   #12
WPDeveloper.com
War Room Member
 
phptechie's Avatar
 
Join Date: 2009
Location: Online
Posts: 88
Thanks: 2
Thanked 9 Times in 7 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Check your PHP version & use appropriate handlers with it version like php3 or php5

phptechie is offline  
Unread 6th Jan 2010, 07:15 AM   #13
Lisa Dozois
War Room Member
 
lisag's Avatar
 
Join Date: 2006
Location: Florida, USA.
Posts: 608
Thanks: 107
Thanked 254 Times in 118 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Originally Posted by BenShaffer View Post

What I want is for my .html files to be parsed as if they are .php

I have tried adding to the .htaccess :

AddHandler x-httpd-php .html .htm

and

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

and

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

The last one actually causes the browser to want me to open it with an application so I know that the .htaccess is being read.

I have also tried adding via the cpanel apache handler.

But it is not parsing it as .php.

So, for example if I use the code:

<?='hello'?>

It is showing as that in the source code.

Any help?

Thanks,

Ben Shaffer
Voon mentioned this earlier, but I don't see where you picked up on it.

where you have
Code:
<?='hello'>
try
Code:
<?PHP='Hello';?>
That should do it for you as long as your .htaccess file is configured properly. Here's what I use:

Code:
AddHandler x-httpd-php .html .htm 
AddHandler php-script .php .html .htm 

AddHandler php5-script .php .html .htm 

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

-- Lisa G
lisag is offline  
Unread 6th Jan 2010, 04:51 PM   #14
HyperActive Warrior
War Room Member
 
Tim Brownlaw's Avatar
 
Join Date: 2009
Location: Berwick, Melbourne, Australia
Posts: 156
Thanks: 5
Thanked 47 Times in 28 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Originally Posted by lisag View Post

Code:
<?PHP='Hello';?>
That's in between the short and long form.

It should be
Code:
<?php echo 'Hello';?>
I always use the long form. That way it will always work between servers. It's not written in stone but I consider it part of my "Good coding practice".

Great Success is built from many little successes!

http://www.timbrownlaw.com - My Wee Part of the World.

http://www.LookingOverMyShoulder.com
Tim Brownlaw is offline  
The Following User Says Thank You to Tim Brownlaw For This Useful Post:
Unread 6th Jan 2010, 05:05 PM   #15
Lisa Dozois
War Room Member
 
lisag's Avatar
 
Join Date: 2006
Location: Florida, USA.
Posts: 608
Thanks: 107
Thanked 254 Times in 118 Posts
Default
Re: Parsing .html as PHP
Share on: 
fb share twitter share gplus share more share

Originally Posted by Tim Brownlaw View Post

That's in between the short and long form.

It should be
Code:
<?php echo 'Hello';?>
I always use the long form. That way it will always work between servers. It's not written in stone but I consider it part of my "Good coding practice".
Right you are and I know better. Sometimes I don't slow down and re-read when I post. Good catch!

Thanks,

Lisa

-- Lisa G
lisag is offline  
Closed Thread


Bookmarks

Tags
html, parsing, php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 04:59 AM.