file extension .php or .html?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Els

    file extension .php or .html?

    If I use <? include "file.html" ; ?> in the html of my
    document, do I _have_ to change the extension of that
    document to .php, or would it still work and be valid if I
    let it remain .html?


    --
    Els

    Mente humana é como pára-quedas; funciona melhor aberta.


  • Zac Hester

    #2
    Re: file extension .php or .html?

    "Els" <els.aNOSPAM@PL EASEtiscali.nl. invalid> wrote in message
    news:biodtj$pfl $1@reader1.tisc ali.nl...[color=blue]
    > If I use <? include "file.html" ; ?> in the html of my
    > document, do I _have_ to change the extension of that
    > document to .php, or would it still work and be valid if I
    > let it remain .html?
    >
    >[/color]

    Apples and oranges. The HTML is valid if the HTML is valid. It's not what
    file name your PHP script has. PHP is _server side_ and HTML is the
    presentation to the browser _after_ all the server side stuff has happened.
    There's not even any reason to ever have a file extension on web content at
    all (except to make the files more friendly to applications that pay
    attention to the file extension--mostly Win32 stuff). In fact, it's common
    practice to create CMS-type scripts with no file extension so the web server
    can reference the resource through a friendlier directory-like URI.

    By adding that one line of PHP code, you have, in fact, created a
    fully-functioning PHP script. This file now requires the HTTP host to
    filter it through the PHP parser. On many HTTP hosts, you can set it to
    only filter *.php files, or you can set it to filter any combination of
    files with a given extension. If your page is working on your server and is
    being processed by the PHP parser, it's fine to leave it with the .html
    extension. If you ever run into a server that does not run all *.html files
    through the parser, your page will not operate correctly until you do one of
    two things:

    1. Change the extension to "php" or...
    2. Change the server's configuration. In Apache, this is as simple as
    adding an .htaccess file with one line of configuration (asking to pass
    *.html files through the parser). Of course, if you're not in control of
    the host, this configuration directive may or may not be allowed to be
    controlled in your local web directory.

    If this is the extent of your PHP code, I would probably just stick to the
    "html" extension. If you get really fancy, it might be more appropriate to
    label the thing with a "php" extension so someone else can maintain your
    site (I know, it probably won't fall into someone else's hands anyway)
    without too much headache.

    HTH,
    Zac


    Comment

    • Els

      #3
      Re: file extension .php or .html?

      Els wrote:[color=blue]
      > Zac Hester wrote:[color=green]
      >> 2. Change the server's configuration. In Apache, this is as simple as
      >> adding an .htaccess file with one line of configuration (asking to pass
      >> *.html files through the parser). Of course, if you're not in control of
      >> the host, this configuration directive may or may not be allowed to be
      >> controlled in your local web directory.
      >>
      >> If this is the extent of your PHP code, I would probably just stick to
      >> the "html" extension. If you get really fancy, it might be more appropriate to label the thing with a "php" extension so someone else can maintain your
      >> site (I know, it probably won't fall into someone else's hands anyway)
      >> without too much headache.
      >>
      >> HTH,[/color]
      >
      > It did. Thanks for this very complete answer, appreciate it :-)[/color]

      ...and now comes the next question ;-)
      I now know, that my server doesn't parse html files as php.
      Can you tell me what that one line of configuration in an
      ..htaccess file would have to be? To what do I 'add' an
      ..htaccess file? To every folder of the website, or only to
      the main (first) one? Or can you give me a link to a clear
      instruction somewhere? I googled, but all I could find was
      someone saying: 'it has been discussed before, so you should
      be able to find it in the archives', but I couldn't find
      anything...

      Thanks,

      --
      Els

      Mente humana é como pára-quedas; funciona melhor aberta.

      Comment

      • Els

        #4
        Re: file extension .php or .html?

        Els wrote:
        [color=blue]
        > Els wrote:
        >[color=green]
        >> Zac Hester wrote:
        >>[color=darkred]
        >>> 2. Change the server's configuration. In Apache, this is as simple as
        >>> adding an .htaccess file with one line of configuration (asking to pass
        >>> *.html files through the parser). Of course, if you're not in
        >>> control of
        >>> the host, this configuration directive may or may not be allowed to be
        >>> controlled in your local web directory.
        >>>
        >>> If this is the extent of your PHP code, I would probably just stick
        >>> to the "html" extension. If you get really fancy, it might be more
        >>> appropriate to label the thing with a "php" extension so someone else
        >>> can maintain your
        >>> site (I know, it probably won't fall into someone else's hands anyway)
        >>> without too much headache.
        >>>
        >>> HTH,[/color]
        >>
        >>
        >> It did. Thanks for this very complete answer, appreciate it :-)[/color]
        >
        >
        > ..and now comes the next question ;-)
        > I now know, that my server doesn't parse html files as php.
        > Can you tell me what that one line of configuration in an .htaccess file
        > would have to be? To what do I 'add' an .htaccess file? To every folder
        > of the website, or only to the main (first) one? Or can you give me a
        > link to a clear instruction somewhere? I googled, but all I could find
        > was someone saying: 'it has been discussed before, so you should be able
        > to find it in the archives', but I couldn't find anything...[/color]

        I did find something: ForceType application/x-httpd-php
        I uploaded it, and my .html files are now parsed as .php,
        but now my images won't display, because of a parse error.

        Anyone know what I should type instead of ForceType
        application/x-httpd-php?

        Thanks,

        --
        Els

        Mente humana é como pára-quedas; funciona melhor aberta.

        Comment

        • John W.

          #5
          Re: file extension .php or .html?

          Els <els.aNOSPAM@PL EASEtiscali.nl. invalid>:
          [color=blue]
          >Els wrote:
          >[color=green]
          >> Els wrote:
          >>[color=darkred]
          >>> Zac Hester wrote:
          >>>
          >>>> 2. Change the server's configuration. In Apache, this is as simple as
          >>>> adding an .htaccess file with one line of configuration (asking to pass
          >>>> *.html files through the parser). Of course, if you're not in
          >>>> control of
          >>>> the host, this configuration directive may or may not be allowed to be
          >>>> controlled in your local web directory.
          >>>>
          >>>> If this is the extent of your PHP code, I would probably just stick
          >>>> to the "html" extension. If you get really fancy, it might be more
          >>>> appropriate to label the thing with a "php" extension so someone else
          >>>> can maintain your
          >>>> site (I know, it probably won't fall into someone else's hands anyway)
          >>>> without too much headache.
          >>>>
          >>>> HTH,
          >>>
          >>>
          >>> It did. Thanks for this very complete answer, appreciate it :-)[/color]
          >>
          >>
          >> ..and now comes the next question ;-)
          >> I now know, that my server doesn't parse html files as php.
          >> Can you tell me what that one line of configuration in an .htaccess file
          >> would have to be? To what do I 'add' an .htaccess file? To every folder
          >> of the website, or only to the main (first) one? Or can you give me a
          >> link to a clear instruction somewhere? I googled, but all I could find
          >> was someone saying: 'it has been discussed before, so you should be able
          >> to find it in the archives', but I couldn't find anything...[/color]
          >
          >I did find something: ForceType application/x-httpd-php
          >I uploaded it, and my .html files are now parsed as .php,
          >but now my images won't display, because of a parse error.
          >
          >Anyone know what I should type instead of ForceType
          >application/x-httpd-php?
          >[/color]
          I have to use the *.php extension if I include any php in the source.

          ..htaccess ? n.i.w.server-side answers, mostly in Dutch :-)
          I can't find yr .htaccess solution very quickly :-(


          John OO
          --

          <http://webcel.nl/>
          <http://www.webcel.nl/bayshop/shop/bayshop.html>

          "Time is what prevents everything from happening at once"
          - John Archibald Wheeler -

          Comment

          • Owen Jacobson

            #6
            Re: file extension .php or .html?

            Els wrote:

            This is all blatantly off-topic. Would someone else please set an
            appropriate followup-to?
            [color=blue]
            > Can you tell me what that one line of configuration in an .htaccess
            > file would have to be?[/color]

            There's a hint in the PHP 'INSTALL' file:

            And finally you need to tell Apache which file extension should
            trigger PHP. You do this by creating a special mime type and
            associating it with an extension. We suggest using:

            AddType application/x-httpd-php .php

            Perhaps you might try

            AddType application/x-httpd-php .html
            [color=blue]
            > To what do I 'add' an .htaccess file? To every folder of the website,
            > or only to the main (first) one?[/color]

            Under apache, .htaccess files affect the directory they are located in
            as well as all subdirectories, barring changes in the subdirectory's
            own htaccess file.
            [color=blue]
            > Or can you give me a link to a clear instruction somewhere?[/color]

            The best instructions you're likely to find are in the manual for your
            specific web server. .htaccess is generally an apache thing, in which
            case you want <http://httpd.apache.or g/docs-project/>.

            Comment

            • Els

              #7
              Re: file extension .php or .html?

              Owen Jacobson wrote:
              [color=blue]
              > Els wrote:
              >
              > This is all blatantly off-topic.[/color]

              It _was_.
              [color=blue]
              > Would someone else please set an
              > appropriate followup-to?[/color]

              There was no follow up, I've redirected the question to
              another newsgroup, as you can see in my message of 31-8-2003
              23:27 :-)
              [color=blue][color=green]
              >>Can you tell me what that one line of configuration in an .htaccess
              >>file would have to be?[/color]
              >
              > There's a hint in the PHP 'INSTALL' file:[/color]

              I have not 'installed' PHP on my computer, I'm dealing with
              the server where my site is being hosted.
              [color=blue]
              > And finally you need to tell Apache which file extension should
              > trigger PHP. You do this by creating a special mime type and
              > associating it with an extension. We suggest using:
              >
              > AddType application/x-httpd-php .php
              >
              > Perhaps you might try
              >
              > AddType application/x-httpd-php .html[/color]

              I did already (and it works as I wanted it to), thanks to
              the answers I got in nl.internet.www w.server-side and
              comp.lang.php :-)
              [color=blue][color=green]
              >>To what do I 'add' an .htaccess file? To every folder of the website,
              >>or only to the main (first) one?[/color]
              >
              > Under apache, .htaccess files affect the directory they are located in
              > as well as all subdirectories, barring changes in the subdirectory's
              > own htaccess file.[/color]

              So I've heard ;-)
              [color=blue][color=green]
              >>Or can you give me a link to a clear instruction somewhere?[/color]
              >
              > The best instructions you're likely to find are in the manual for your
              > specific web server. .htaccess is generally an apache thing, in which
              > case you want <http://httpd.apache.or g/docs-project/>.[/color]

              Thanks,

              --
              Els

              Mente humana é como pára-quedas; funciona melhor aberta.

              Comment

              Working...