Purpose of a ".inc" file?

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

    Purpose of a ".inc" file?

    If a file has a .inc extension, or if it has a .inc.php extension, is it
    treated differently by the php interpreter? Or is it just a convention?

    I've been calling my included files filename.php and it doesn't seem to
    hurt anything. Is it wrong to do that?

    E

  • Jan Pieter Kunst

    #2
    Re: Purpose of a ".inc&quot ; file?

    In article <eKRab.22897$dk 4.716820@typhoo n.sonic.net>,
    Phester <elektrophyte@t hesearentthedro idsyourelooking for.yahoo.com>
    wrote:
    [color=blue]
    > If a file has a .inc extension, or if it has a .inc.php extension, is it
    > treated differently by the php interpreter? Or is it just a convention?
    >
    > I've been calling my included files filename.php and it doesn't seem to
    > hurt anything. Is it wrong to do that?
    >
    > E[/color]

    The .php extension is for the webserver. It doesn't matter to PHP (or
    the webserver) what the extension of an include file is, but the
    extension of the main file must be recognizable as PHP to the webserver.

    It's a good idea to give include files also .php as the final extension
    for security reasons: if the include file is called directly in a web
    browser, the webserver might show the contents of the file as text if it
    doesn't recognize its extension. If it has a .php extension the source
    code will not be visible.

    ..inc.php is just a convention.

    JP

    --
    Sorry, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    • Ian.H [dS]

      #3
      Re: Purpose of a &quot;.inc&quot ; file?

      On Sat, 20 Sep 2003 06:39:22 +0000, Phester wrote:
      [color=blue]
      > If a file has a .inc extension, or if it has a .inc.php extension, is it
      > treated differently by the php interpreter? Or is it just a convention?
      >
      > I've been calling my included files filename.php and it doesn't seem to
      > hurt anything. Is it wrong to do that?
      >
      > E[/color]


      ..php (by default) is the normal extension for files.

      ..inc was (/ still is?) used normally for files being used in include() or
      require() calls that reside on a remote server. Including a .php file from
      a remote server causes problems as it's retrieved as a parsed file, so you
      only retrieve the HTML output, rather than the PHP code you really want.
      As .inc isn't normally assigned in the server configuration, this will
      normally return as a text/plain file, meaning that all the PHP code is
      available when included.

      I've never needed to use .inc files personally for remote retrieval, some
      seemed to use it in the earlier days for files include()d regardles of
      them being local or remote.. personally I prefer .php wherever I can to
      prevent accidental viewing of code.



      Regards,

      Ian

      --
      Ian.H [Design & Development]
      digiServ Network - Web solutions
      www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
      Programming, Web design, development & hosting.

      Comment

      • Phester

        #4
        Re: Purpose of a &quot;.inc&quot ; file?

        > On Sat, 20 Sep 2003 06:39:22 +0000, Phester wrote:[color=blue]
        >
        >[color=green]
        >>If a file has a .inc extension, or if it has a .inc.php extension, is it
        >>treated differently by the php interpreter? Or is it just a convention?
        >>[/color][/color]

        ....

        Jan Pieter Kunst wrote:[color=blue]
        > The .php extension is for the webserver. It doesn't matter to PHP (or
        > the webserver) what the extension of an include file is, but the
        > extension of the main file must be recognizable as PHP to the webserver.
        >
        > It's a good idea to give include files also .php as the final extension
        > for security reasons: if the include file is called directly in a web
        > browser, the webserver might show the contents of the file as text if it
        > doesn't recognize its extension. If it has a .php extension the source
        > code will not be visible.
        >
        > .inc.php is just a convention.
        >
        > JP[/color]

        ....

        Ian.H [dS] wrote:
        [color=blue]
        > .php (by default) is the normal extension for files.[/color]
        [color=blue]
        > .inc was (/ still is?) used normally for files being used in include() or
        > require() calls that reside on a remote server. Including a .php file from
        > a remote server causes problems as it's retrieved as a parsed file, so you
        > only retrieve the HTML output, rather than the PHP code you really want.[/color]


        Thanks for the replies. Now it makes sense.

        Phester

        Comment

        • Ivo

          #5
          Re: Purpose of a &quot;.inc&quot ; file?

          "Phester" <elektrophyte@t hesearentthedro idsyourelooking for.yahoo.com> wrote:[color=blue][color=green]
          > > On Sat, 20 Sep 2003 06:39:22 +0000, Phester wrote:[/color]
          > Jan Pieter Kunst wrote:[color=green]
          > > The .php extension is for the webserver. It doesn't matter to PHP (or
          > > the webserver) what the extension of an include file is, but the
          > > extension of the main file must be recognizable as PHP to the[/color][/color]
          webserver.[color=blue][color=green]
          > >
          > > It's a good idea to give include files also .php as the final extension
          > > for security reasons: if the include file is called directly in a web
          > > browser, the webserver might show the contents of the file as text if[/color][/color]
          it[color=blue][color=green]
          > > doesn't recognize its extension. If it has a .php extension the source
          > > code will not be visible.
          > >
          > > .inc.php is just a convention.
          > >
          > > JP[/color]
          > Ian.H [dS] wrote:[color=green]
          > > .php (by default) is the normal extension for files.
          > > .inc was (/ still is?) used normally for files being used in include()[/color][/color]
          or[color=blue][color=green]
          > > require() calls that reside on a remote server. Including a .php file[/color][/color]
          from[color=blue][color=green]
          > > a remote server causes problems as it's retrieved as a parsed file, so[/color][/color]
          you[color=blue][color=green]
          > > only retrieve the HTML output, rather than the PHP code you really want.[/color]
          >
          > Thanks for the replies. Now it makes sense.
          > Phester
          >[/color]
          To prevent viewing of inc files, put this in an .htaccess file:
          <Files ~ "\.inc$">
          Order allow,deny
          Deny from all
          </Files>

          To prevent viewing of the .htaccess file:
          <Files ~ "^\.htacces s$">
          Order allow,deny
          Deny from all
          </Files>

          Will result in File not Found errors when such file is requested directly,
          even though it may well be there!
          In Apache 1.3 (I think) FilesMatch is preferred instead of Files.
          Ivo


          Comment

          Working...