Forum Moderators: coopster

Message Too Old, No Replies

Naming include fles

.inc, .txt, .php, .html

         

D_Blackwell

2:00 am on Aug 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a couple of projects going that have some php includes. Between them (and some on my own sites), nearly every possilbe extension is represented, which prompts me ask about the general consensus for 'best practice'.

Over time, I've taken to .inc, but I like to hear other's thoughts.

encyclo

2:04 am on Aug 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tend to use the format
include.inc.php
- assuming the included file has PHP code within it, then using .php means that if anyone were to find a way of loading the file directly in the browser (ie. not as an included file) then the contents wouldn't show as source code.

chrisjoha

8:07 am on Aug 2, 2005 (gmt 0)

10+ Year Member



If you have access to the server configuration it's not a security problem; you could just deny the direct listing of an include file and call whatever you want. In that case I think it's just a matter of convention - stick to one. If it's possible that the site will ever be moved to a server in which you won't be able to control, I would stick with php (or inc.php) so as to prevent the include files from being accessed directly.

dcrombie

8:50 am on Aug 2, 2005 (gmt 0)



Using .inc is a good choice, as long as the webserver is (and always will be) configured not to allow direct access to .inc files. They should in any case not be parsed by PHP as running an 'include file' by itself can have unpredictable results.

That can be a problem if you use .php or .inc.php as suggested above.

;)

jatar_k

3:12 pm on Aug 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if these files are to be included only and not requested directly then they should be above the web root as well.

I use these for mine

.inc.php
.lib.php

coopster

12:25 am on Aug 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> .lib.php

must be a carryover, are you some sort of old Perl hack? ;)

madmac

1:16 am on Aug 3, 2005 (gmt 0)

10+ Year Member



I tend to follow the common sense practice that you use the correct extension for a file... for php 4 or higher, this is .php; for php 3 it is .php3; for plain-text it is .txt; etc ;)

.inc.php seems ok to me as well, but personally I prefer to keep all of my library files outside of the doc root in a folder (either like lib/ or inc/) and then further sub-divide that into folders that make sense and house the relevant scripts (classes/, pages/, utilities/, etc). And just use plain old .php

Personally, I cannot stand when I download a project and they have not used .php for php files. If you open a php file in any standard editor that has the extension .inc, it will not open it as a php file, but as just a plain-text file, which depending on the editor could leave you crippled until you either tell the program to read it as php (if you can), or rename it .inc.php or .php to edit it, and then back to just .inc so the app doesn't break...

Really, whatever suits your fancy, but if other people will be using the files, the last part should always be .php