difference between .inc and .php files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidklonski
Forum Contributor
Posts: 128
Joined: Mon Mar 22, 2004 4:55 pm

difference between .inc and .php files

Post by davidklonski »

Hello

I have noticed that many people put their php code in .inc files while others put it in .inc files.

Can someone tell me what are the differences between the two methods and when should I prefer one over the other?

thanks
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

There's no real difference. People just use .inc to indicate that the file is an included one. I prefere just to stick to .php

Also a default server setup is set not to parse .inc files as php files, so if you have a .inc file in your document root it could be possible to view the code in it and reveal sensitive information. You could always use .inc.php and get the best of both worlds.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

markl999 wrote:There's no real difference.
On the contrary..
markl999 wrote:Also a default server setup is set not to parse .inc files as php files, so if you have a .inc file in your document root it could be possible to view the code in it and reveal sensitive information. You could always use .inc.php and get the best of both worlds.
Thats a serious and signifigant difference - .inc by default is NOT parsed, and so can (usually) be viewed directly.

A novice hearing "there is no difference" might be tempted to put sensitive data there. Bad idea.

Definitely a real difference, and thats how the server handles them - inc is (usually) served plain-text, php is parsed.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Yeah, by "There's no real difference." i meant functionally, i should have been clearer. A novice might be tempted, which is why i explained the default setup issue.
But fair point i suppose ;)
Chambrln
Forum Commoner
Posts: 43
Joined: Tue Dec 02, 2003 10:45 am
Location: Oregon

Post by Chambrln »

If you use .inc files you should make sure your webserver parses them as .php files.

As stated by the previous posts you don't want your database username and password in your .inc file and then have someone be able to read it plain text.

You can test this by putting a .inc file on your server and calling it directly from the web browser. To be safe you can just use .php as was previously stated.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

or put them outside of the webserver, right?
Findus
Forum Newbie
Posts: 7
Joined: Tue Apr 20, 2004 8:47 am

Post by Findus »

As said php doesnt by default parse .inc files.
Personaly i think using .inc as in include is wrong. It is a include file yes, but its php aswell. I like to use .inc.php easiest. And in the same way: .class.php.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Findus wrote:As said php doesnt by default parse .inc files.
Personaly i think using .inc as in include is wrong. It is a include file yes, but its php aswell. I like to use .inc.php easiest. And in the same way: .class.php.
Agree with that
Post Reply