homepage Welcome to WebmasterWorld Guest from 54.196.159.11
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
question regarding PHP code in .htm files instead of .php extension
is this advisable?
ebess




msg:1263372
 6:35 am on Aug 8, 2001 (gmt 0)

I am just starting to learn PHP and many of the tutorials that I have come across provide sample code to be embedded into your .htm file. To me, this implies that the server should be able to recognize that the parsed PHP code, delineated by it's <? and ?>, and process that along with the html.

When I try this on my server, however, it doesn't work (although it works fine if I rename the file to something.php instead of something.htm)

I would rather use .htm extension though, as I think it's better for search engines and I don't care to notify folks that I'm doing anything dynamic in the background by having the php extension.

I was able to get this to work by modifying my .htaccess file to add a line as follows:

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

So I guess my real questions are:

1) Is it normally necessary to add this line to your .htaccess file in order to process PHP in .htm files?

2) Is there any reason NOT to add this line to my .htaccess file? In other words, is there any reason (performance, security, whatever..) why I wouldn't want my server to process .htm files with PHP code in them?

As I mentioned, I'm just getting started with this so forgive me if the question seems a bit inane..

Thanks for any help that can be provided :)

-ebess-

 

sugarkane




msg:1263373
 12:16 pm on Aug 8, 2001 (gmt 0)

> Is it normally necessary to add this line to your .htaccess file

Yes :)

You need to tell the server which files to run through the PHP engine, and that is the way you do it.

> Is there any reason NOT to add this line to my .htaccess file

You'll take a performance hit on non-PHP .htm pages as they'll still be parsed for PHP coding. If most of your pages are straight HTML then you'd probably be better off putting your PHP pages in a seperate directory and only putting the .htaccess file in there.

ebess




msg:1263374
 6:26 pm on Aug 8, 2001 (gmt 0)

thanks, sugarkane, for your help! that was exactly what I needed to know :)

-ebess-

WebGuerrilla




msg:1263375
 6:44 pm on Aug 8, 2001 (gmt 0)


If you need to use PHP throughout various locations in your site and putting them all in the same directory isn't advisable, you can add just one html extension to your .htaccess

If all your current pages are .htm then you could just add

AddType application/x-httpd-php .php .php3 .phtml .html

And then just rename the pages containing the PHP to .html That way, the non-php pages won't get parsed.

ebess




msg:1263376
 7:07 pm on Aug 8, 2001 (gmt 0)

even better!

that's brilliant

thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved