This is a discussion on Make all pages .php? within the PHP Language forums, part of the PHP Programming Forums category; This is a best practices question. For a website where PHP is used, does it make sense to have both ....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
This is a best practices question.
For a website where PHP is used, does it make sense to have both .htm and .php files? In other words, for pages that have no active content there's no point in naming them with a .php extension. Is there any advantage or disadvantage to making all files .php, or the same for mixing them with .htm files? What do you do, and why? Thanks for your input. |
|
|||
|
On Wed, 17 Sep 2003 10:52:52 -0400, Bruce W...1 wrote:
> This is a best practices question. > > For a website where PHP is used, does it make sense to have both .htm and .php > files? In other words, for pages that have no active content there's no point > in naming them with a .php extension. > > Is there any advantage or disadvantage to making all files .php, or the same for > mixing them with .htm files? Slight speed disadvantage to making all files .php. > What do you do, and why? Make everything a .phtml file (set up in Apache to be the same as .php). The speed disadvantage is unnoticable and it means if I have to add some dynamic content to a page I don't have to change every link to it. However, my recent sites are virtually object generated so every page has objects in it that form the layout. Cheers, Andy |
|
|||
|
Bruce W...1 wrote:
> This is a best practices question. > > For a website where PHP is used, does it make sense to have both .htm and .php > files? In other words, for pages that have no active content there's no point > in naming them with a .php extension. > > Is there any advantage or disadvantage to making all files .php, or the same for > mixing them with .htm files? > > What do you do, and why? > All my pages are PHP Here are my reasons: - I'm using sessions. If the user only plays with .htm URLs for a small period, the session will expire, and it shouldn't expire since the user is still using the site. - If the user doesn't support cookies, the session ID will be transmitted by PHP in URLs (URL rewriting). Plain HTML pages will thus lose the session. - I use PHP to have a coherent look for all the pages. The header, left menu, right menu and footer of all the pages are the same, and are each defined in their own single PHP file, which are included by PHP. Using HTML would force me to hardcode all these parts in every HTML page, which would lead to a maintenance nightmare. JB. > Thanks for your input. |
|
|||
|
> This is a best practices question. > > For a website where PHP is used, does it make sense to have both .htm > and .php files? In other words, for pages that have no active content > there's no point in naming them with a .php extension. > > Is there any advantage or disadvantage to making all files .php, or the > same for mixing them with .htm files? I am a strong believer that, for best practice, one should never use .php but use .html instead. Certainly using a mixture is asking for trouble. The same applies to nasty extensions like .php3, .php4, .phtml and the like. Using .php advertises your server technology, is less familiar to people if you are having to print an address, results in you having to change all your URLs if you then decide to change to some other technology, and can result in a mixture of .html and .php. Also, if you then decide to add bits of PHP to an existing .html file you don't then have to change the URL (and mess about with redirections). Given that many sites these days will be using PHP for some sort of house style use (as well as anything else..) PHP will, by definition, need to be parsing most if not all files. Therefore, set .html to be parsed for PHP. I've never encountered any noticable performance hit, even on sites that barely make use of the PHP parser. I dare say there might be on an extremely busy site, but I suspect most people would never run into that and the above maintenance advantages outweigh the disadvantages. Just add AddType application/x-httpd-php .html to your .htaccess file or Apache config. What could be simpler? Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22 www.lucas-smith.co.uk |
|
|||
|
Martin Lucas-Smith wrote:
> > I am a strong believer that, for best practice, one should never use .php > but use .html instead. Certainly using a mixture is asking for trouble. > The same applies to nasty extensions like .php3, .php4, .phtml and the > like. > > Using .php advertises your server technology, is less familiar to people > if you are having to print an address, results in you having to change all > your URLs if you then decide to change to some other technology, and can > result in a mixture of .html and .php. Also, if you then decide to add > bits of PHP to an existing .html file you don't then have to change the > URL (and mess about with redirections). > > Given that many sites these days will be using PHP for some sort of house > style use (as well as anything else..) PHP will, by definition, need to be > parsing most if not all files. Therefore, set .html to be parsed for PHP. > > I've never encountered any noticable performance hit, even on sites that > barely make use of the PHP parser. I dare say there might be on an > extremely busy site, but I suspect most people would never run into that > and the above maintenance advantages outweigh the disadvantages. > ================================================== =========== That makes sense, but how do you set .html to be parsed for PHP? I'm using IIS on Windows 2000. I suspect this is done in IIS? If that's the case I'm screwed because I use a hosting company (also running Win 2000) and they would not let me access the IIS settings. But perhaps they already have it setup this way, I'll ask. Thanks. > Just add > > AddType application/x-httpd-php .html > > to your .htaccess file or Apache config. What could be simpler? > > Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22 > www.lucas-smith.co.uk |
|
|||
|
Jean-Baptiste Nizet wrote:
> > All my pages are PHP > > Here are my reasons: > - I'm using sessions. If the user only plays with .htm URLs for a small > period, the session will expire, and it shouldn't expire since the user > is still using the site. > - If the user doesn't support cookies, the session ID will be > transmitted by PHP in URLs (URL rewriting). Plain HTML pages will thus > lose the session. > - I use PHP to have a coherent look for all the pages. The header, left > menu, right menu and footer of all the pages are the same, and are each > defined in their own single PHP file, which are included by PHP. Using > HTML would force me to hardcode all these parts in every HTML page, > which would lead to a maintenance nightmare. > > JB. > ================================================== ========= Very good point. The session state is an overwhelming reason. I'm new to PHP. Can you point me to information on how to put the common page elements in separate files, assuming you are not using frames? Can this be done without using frames? I know that a similar ability is done with ASP.NET User Controls. Thanks. |
|
|||
|
bruce, i'm pretty new to php, however, i use php includes to keep my
repetitive html code in one location (ex, header, menu bars, footer). since all my pages use includes, they have are .php. if you aren't using includes for repetitive html code, i recommend you do so. if you hve straight html, my bet is to not to use .php if you have no php code b/c it doesn't make sense to send those pages to the php processor - that's inefficient. "Bruce W...1" <bruce@noDirectEmail.com> wrote in message news:<3F687544.D957C328@noDirectEmail.com>... > This is a best practices question. > > For a website where PHP is used, does it make sense to have both .htm and .php > files? In other words, for pages that have no active content there's no point > in naming them with a .php extension. > > Is there any advantage or disadvantage to making all files .php, or the same for > mixing them with .htm files? > > What do you do, and why? > > Thanks for your input. |
|
|||
|
bruce, it works like this...
<?PHP INCLUDE ('includes/logoHeader.inc.php'); INCLUDE ('includes/hNavBar.inc.php'); INCLUDE ('includes/vNavBar.inc.php'); ?> i have three files in a my include folder. One for the header, one for the horizontal navigation bar and one for the vertical one. just put your plain old vanilla html code into the logoHeader.inc.php file. php will bring it in as is. i put these "includes" on every page. "Bruce W...1" <bruce@noDirectEmail.com> wrote in message news:<3F6893F5.57777EF1@noDirectEmail.com>... > Jean-Baptiste Nizet wrote: > > > > All my pages are PHP > > > > Here are my reasons: > > - I'm using sessions. If the user only plays with .htm URLs for a small > > period, the session will expire, and it shouldn't expire since the user > > is still using the site. > > - If the user doesn't support cookies, the session ID will be > > transmitted by PHP in URLs (URL rewriting). Plain HTML pages will thus > > lose the session. > > - I use PHP to have a coherent look for all the pages. The header, left > > menu, right menu and footer of all the pages are the same, and are each > > defined in their own single PHP file, which are included by PHP. Using > > HTML would force me to hardcode all these parts in every HTML page, > > which would lead to a maintenance nightmare. > > > > JB. > > > ================================================== ========= > > Very good point. The session state is an overwhelming reason. > > I'm new to PHP. Can you point me to information on how to put the common page > elements in separate files, assuming you are not using frames? Can this be done > without using frames? > > I know that a similar ability is done with ASP.NET User Controls. > > Thanks. |
|
|||
|
No my hosting company does not have IIS set for PHP to parse HTML files, though
I can request this. If you really want to hide your technology there's an easier way. At your domain registrar have the name server forward with masking. This hides all file names. |