Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Parsing .html as PHP (https://www.warriorforum.com/programming/162876-parsing-html-php.html)

BenShaffer 5th January 2010 03:52 AM

Parsing .html as PHP
 
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 5th January 2010 04:21 AM

Re: Parsing .html as PHP
 
I use this in .htaccess

Code:

<FilesMatch ".(htm|html)$">
  SetHandler application/x-httpd-php
  ForceType application/x-httpd-php
</FilesMatch>

Quote:

Originally Posted by BenShaffer (Post 1577428)
<?='hello'?>

This would require 'short_open_tag' enabled in PHP.

BenShaffer 5th January 2010 04:28 AM

Re: Parsing .html as PHP
 
Thanks. Weirdly, this is causing the browser to ask how to open the file.

Any other suggestions?

Ben Shaffer

Tim Brownlaw 5th January 2010 06:08 AM

Re: Parsing .html as PHP
 
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

BenShaffer 5th January 2010 07:12 AM

Re: Parsing .html as PHP
 
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

KirkMcD 5th January 2010 09:11 AM

Re: Parsing .html as PHP
 
Quote:

Originally Posted by BenShaffer (Post 1577428)
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.

BenShaffer 5th January 2010 09:40 AM

Re: Parsing .html as PHP
 
Kirk,

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

B

Ross Dalangin 5th January 2010 11:19 AM

Re: Parsing .html as PHP
 
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

Ken Shorey 5th January 2010 02:50 PM

Re: Parsing .html as PHP
 
If your host is running php version 5, you should try:
AddType application/x-httpd-php5 .html .htm

Tim Brownlaw 5th January 2010 04:05 PM

Re: Parsing .html as PHP
 
Quote:

Originally Posted by BenShaffer (Post 1577872)
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

mlangille 5th January 2010 05:42 PM

Re: Parsing .html as PHP
 
Hey Ben

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


Michael

phptechie 6th January 2010 05:10 AM

Re: Parsing .html as PHP
 
Check your PHP version & use appropriate handlers with it version like php3 or php5

lisag 6th January 2010 07:15 AM

Re: Parsing .html as PHP
 
Quote:

Originally Posted by BenShaffer (Post 1577428)
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


Tim Brownlaw 6th January 2010 04:51 PM

Re: Parsing .html as PHP
 
Quote:

Originally Posted by lisag (Post 1582779)
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".

lisag 6th January 2010 05:05 PM

Re: Parsing .html as PHP
 
Quote:

Originally Posted by Tim Brownlaw (Post 1585303)
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


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