Make all pages .php?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce W...1

    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.
  • Andy Jeffries

    #2
    Re: Make all pages .php?

    On Wed, 17 Sep 2003 10:52:52 -0400, Bruce W...1 wrote:[color=blue]
    > 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?[/color]

    Slight speed disadvantage to making all files .php.
    [color=blue]
    > What do you do, and why?[/color]

    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

    Comment

    • Jean-Baptiste Nizet

      #3
      Re: Make all pages .php?

      Bruce W...1 wrote:
      [color=blue]
      > 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?
      >[/color]

      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.
      [color=blue]
      > Thanks for your input.[/color]

      Comment

      • Martin Lucas-Smith

        #4
        Re: Make all pages .php?



        [color=blue]
        > 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?[/color]

        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




        Comment

        • Bruce W...1

          #5
          Re: Make all pages .php?

          Martin Lucas-Smith wrote:[color=blue]
          >
          > 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.
          >[/color]
          =============== =============== =============== =============== =

          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.[color=blue]
          > 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[/color]

          Comment

          • Bruce W...1

            #6
            Re: Make all pages .php?

            Jean-Baptiste Nizet wrote:[color=blue]
            >
            > 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.
            >[/color]
            =============== =============== =============== ==============

            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.

            Comment

            • Jeff Skeith

              #7
              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@noDirect Email.com> wrote in message news:<3F687544. D957C328@noDire ctEmail.com>...[color=blue]
              > 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.[/color]

              Comment

              • Jeff Skeith

                #8
                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@noDirect Email.com> wrote in message news:<3F6893F5. 57777EF1@noDire ctEmail.com>...[color=blue]
                > Jean-Baptiste Nizet wrote:[color=green]
                > >
                > > 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.
                > >[/color]
                > =============== =============== =============== ==============
                >
                > 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.[/color]

                Comment

                • Bruce W...1

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

                  Comment

                  • Bruce W...1

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

                    Comment

                    • Jeff Skeith

                      #11
                      Re: Make all pages .php?

                      bruce, why not go with apache? it is pretty simple to set up on
                      windows. do a google for apache install tutorial on win2000. php was
                      designed to work with apache.

                      also, i kinda like the idea of making html files automatically go to
                      the php processor. i think i'll set my site up like that in which
                      case all my files will be html and all will be php processed since
                      that's a requirement anyway due to my include statements.

                      "Bruce W...1" <bruce@noDirect Email.com> wrote in message news:<3F6892BF. 7526E047@noDire ctEmail.com>...[color=blue]
                      > Martin Lucas-Smith wrote:[color=green]
                      > >
                      > > 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.
                      > >[/color]
                      > =============== =============== =============== =============== =
                      >
                      > 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.[color=green]
                      > > 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[/color][/color]

                      Comment

                      • Adams-Blake Co.

                        #12
                        Re: Make all pages .php?

                        Jean-Baptiste Nizet wrote:

                        [color=blue][color=green]
                        >> 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?
                        >>[/color]
                        >
                        > 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.[/color]

                        I have to question this. Where is this documented? I did some testing. I have
                        a aaaa.php page with a pop-up link (_blank) that passes a querystring to
                        bbb.php page which does a header redirect to an myhelp.html "help" screen. I
                        can close the pop-up and my session variables have not gone away and my
                        application continues to function normally

                        Even if I had a link from a php page to an .html page, I don't see where the
                        server would know to cancel the session.

                        I'm not saying you are wrong, its just that I have not experienced this. Have
                        others?

                        Al






                        [color=blue]
                        > - 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.
                        >[color=green]
                        >> Thanks for your input.[/color][/color]

                        Comment

                        • Jean-Baptiste Nizet

                          #13
                          Re: Make all pages .php?

                          Adams-Blake Co. wrote:
                          [color=blue]
                          > Jean-Baptiste Nizet wrote:
                          >
                          >
                          >[color=green][color=darkred]
                          >>>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?
                          >>>[/color]
                          >>
                          >>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.[/color]
                          >
                          >
                          > I have to question this. Where is this documented? I did some testing. I have
                          > a aaaa.php page with a pop-up link (_blank) that passes a querystring to
                          > bbb.php page which does a header redirect to an myhelp.html "help" screen. I
                          > can close the pop-up and my session variables have not gone away and my
                          > application continues to function normally
                          >
                          > Even if I had a link from a php page to an .html page, I don't see where the
                          > server would know to cancel the session.
                          >
                          > I'm not saying you are wrong, its just that I have not experienced this. Have
                          > others?
                          >
                          > Al
                          >
                          >[/color]

                          It's simple. Here's how sessions work: each time session_start() is
                          called, PHP updates a timestamp associated with the session ID contained
                          in the session cookie (or in the URL is URL rewriting is used). If
                          session_start() is not called for, let's say 20 minutes, and if PHP is
                          configured to time out sessions after, let's say 10 minutes, then the
                          next time session_start() is called, the session has been removed.
                          So, if during the 20 minutes you're still browsing the web site without
                          calling any PHP page, session_start() will never be called, and the
                          session will be lost.

                          look at http://www.php.net/manual/en/ref.session.php for more details.

                          JB.

                          Comment

                          • Tim Tyler

                            #14
                            Re: Make all pages .php?

                            Martin Lucas-Smith <mvl22@cam.ac.u k> 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.

                            Using:

                            DirectoryIndex index.html index.jsp index.shtml index.php index.htm

                            ....in Apache encapsulates the server-side technology you use fairly well.

                            Using URLs with .php in them seems like a questionable practice to me -
                            but then so it using URLs with .html in them - for the same reason.

                            I don't think using the ".html" file extension for PHP files is a good
                            way to deal with the issue.
                            --
                            __________
                            |im |yler http://timtyler.org/ tim@tt1.org

                            Comment

                            • Martin Lucas-Smith

                              #15
                              Re: Make all pages .php?


                              [color=blue]
                              > i put these "includes" on every page.[/color]

                              Consider using auto_prepend_fi le and auto_append_fil e in your .htaccess
                              file or Apache config if you are using Apache, to save yourself the
                              bother. Then your actual pages need only be content without having server
                              includes all over the place.



                              has some further info.



                              Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22



                              Comment

                              Working...