Can I mix PHP and HTML web pages?

He has: 57 posts

Joined: Dec 2004

I'm currently building a new site which will incorporate a bunch of PHP scripts.

Obviously the webpages which contain these scripts must end with .php ... but I was wondering something. Can I use both the .html and .php extensions (depending on the page) for the same site? In other words, I will use the .php extension for those pages that require it, but for all of the other pages can I just continue to use the .html extension? Is this acceptable?

Another related question I have is... if I used the .php extension with ALL of my webpages in the site will it cause any problems with the pages that don't have any PHP code in them? If I did this, would I then have to include the following code

<?php
 
?>
somewhere in the page "just to be sure"?

Thanks for any assistance, I'm new to PHP but excited to be able to use it.

Busy's picture

He has: 6,151 posts

Joined: May 2001

Just add

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

to your .htaccess file and you can just use .html or .phtml file extensions for all pages
if you just opt for .php extension there is no worry about jumping in and out of php via the tags you noted, infact it's faster to use just html when there are no php queries in a block

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.