Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extension and component files

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
A friend of mine just called me to ask me

Q. What extension should I use for component files?

My answer was "no clue" and I guess it would depend on the component itself.

Could you please provide some light into this? I am now curious about it and would like to learn as much as possible on this subject.

Thanks!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
what is a component file? at a guess you mean the middle-layer of code that interacts with the data layer and presentation layer? i.e. 'the guts'. the following is based on this assumption.

from a php perspective it's irrelevant. included files can be included whatever the extension. the only relevant thing is to have the code within <?php ... ?> tags. for an 'executed' file, the extension can be whatever you want so long as you have told your webserver to send those extensions via php.

however, there is a degree of sense in having _all_ code files use a .php extension. the reason is that if those files are under the webroot and someone decides to navigate directly to that file, nothing of the code will be displayed to the user as it will all be parsed by php. if the file had a .txt extension, it would either be downloaded as a file or exposed inline. of course, you can also configure most webservers _not_ to serve certain files.

convention is (i think) that main php files and includes should have .php extensions (by all means put include() files into a separate directory), config files should sit outside the webroot and template files often have .tpl extensions. you then make sure that your webserver will not serve tpl files (of course).
 
I know some people use double extensions, like:
.inc.php

Others do like Jpadie mention, use .htaccess file for telling the web-server that it is to be processed as PHP.

Also, you can include whatnot.

jpadie has an excellent point, especially when considering that most people migrate web-hosts from time to other, which means it's less dependent on configuration and it's therefore both more flexible, and (potentially) more secure.

My personal preference, is that files which are to be included, i usually either put in an includes/ subfolder, or I give them an underscore as pretext in the name.

eg:
_functions.php
functions.inc.php
include/functions.php
include/_functions.php
inc/_func.php

etc.. many ways to go about it :) But I prefer keeping the .php as extension, mostly due to the things also pointed out by jpadie.

Then you will get it sorted - in the FTP client, by filename and/or folder-structure.

Olav Alexander Mjelde
 
Also, in the function file(s), components, etc. check if the script is "it self", eg. if someone directly accesses it, it should die();

Olav Alexander Mjelde
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top