Make all pages .php?

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 ....


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-17-2003
Bruce W...1
 
Posts: n/a
Default Make all pages .php?

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.
Reply With Quote
  #2 (permalink)  
Old 09-17-2003
Andy Jeffries
 
Posts: n/a
Default Re: Make all pages .php?

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
Reply With Quote
  #3 (permalink)  
Old 09-17-2003
Jean-Baptiste Nizet
 
Posts: n/a
Default Re: Make all pages .php?

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.


Reply With Quote
  #4 (permalink)  
Old 09-17-2003
Martin Lucas-Smith
 
Posts: n/a
Default Re: Make all pages .php?




> 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



Reply With Quote
  #5 (permalink)  
Old 09-17-2003
Bruce W...1
 
Posts: n/a
Default Re: Make all pages .php?

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

Reply With Quote
  #6 (permalink)  
Old 09-17-2003
Bruce W...1
 
Posts: n/a
Default Re: Make all pages .php?

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.
Reply With Quote
  #7 (permalink)  
Old 09-17-2003
Jeff Skeith
 
Posts: n/a
Default Re: Make all pages .php?

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.

Reply With Quote
  #8 (permalink)  
Old 09-18-2003
Jeff Skeith
 
Posts: n/a
Default Re: Make all pages .php?

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.

Reply With Quote
  #9 (permalink)  
Old 09-18-2003
Bruce W...1
 
Posts: n/a
Default Re: Make all pages .php?

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.
Reply With Quote
  #10 (permalink)  
Old 09-18-2003
Bruce W...1
 
Posts: n/a
Default Re: Make all pages .php?

Thanks. I'm now learning about this, it's a very good idea. Never realized
that includes can be used with straight html files as well. I thought it was
just an ASP thing. In ASP.NET they are now called User Controls.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:57 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0