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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filenaming (file.inc or file.inc.php)?

Status
Not open for further replies.

JCrou82

Programmer
Aug 23, 2002
265
US
I was just wondering. Is there a difference between creating a file and giving it a .inc extension or a .inc.php extension? Let say I want to create to a database. I want to use this connection on multiple pages so I create an include file that has my database server, username and password and I save the file. Is there a difference in anything, ie processing time and security of the file extension used. I've noticed that on some hosts you can't view the .inc file while on others the .inc file is translated on the browser as a plain text file. (mysite.com/directory/file.inc). Whereas if I save it as a .inc.php file, it'll attempt to run the code, but if the code is dependant on another file, it'll print out the contents of the file.
Any posts on this issue would be greatly appreciated.

Thank you
 
Dont use .inc extension as it will display the content of the file on the browser.

filename.inc.php extension, lets u know that its an included file,not like any other php file .
if the extension is .php the server will try to execute the file when open in the browser like so there shd not be any print statment in these types of files so that it will show u just a bkank page.

i will go for '.inc.php'

cheers

spookie --------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
A couple of things with include().

PHP doesn't care what the file is called. It doesn't have to have the .php or the .inc extension -- you can issue "include('file.foo')" and if that file contains valid PHP code, PHP will execute it.

include() can include a file from anywhere in the filesystem. If you have an included file that contains sensitive information, put it somewhere outside the root of that virtual web server. It makes it that much harder for hostile agencies to get to your information. You only have to make sure that the user under which your web server runs has permission to read the file. ______________________________________________________________________
TANSTAAFL!
 
The differences you saw all depend on how the web server is configured. Some are configured to show .inc files at all. Others interpret them the same as .php files. Still others don't know how to handle them, and thus display them in the browser as text. The same way that you tell a server how to handle .php and .php3 files, you can tell it to handle any file type with an interpreter.

Heck, if you wanted, you could make your server work where all files that had an extension of .mynameisfred as PHP files. Not very efficient, but it would work.

As for include(), as sleipnir says above, PHP doesn't care what extension you use for your include files, as long as you have the extension in the file name in the include() statement.
--
How can you be in two places at once when you're not anywhere at all?
 
if you want use inc extention you may create .htaccess file:
<Files *.inc>
Order Deny
Deny from all
</Files>

____________________
Sincerely,
Valeriy Shvec
AlarIT programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top