Click to See Complete Forum and Search --> : Difference between .php and .inc
jamesm6162
01-06-2008, 08:34 AM
Hi
when it comes to including files in your script, what is the difference between .inc and .php files.
When should each be used?
callumd
01-06-2008, 09:26 AM
It is important that your main PHP script has a file name that ends with .php. If you don't do this, then the web server may not even realise that your file is a PHP file, meaning your web page may not display properly when you try to access it in a web browser.
If you are writing a PHP script, and you want to include an external file, you can actually use any name at all for your include files. So, you could use filename.inc
However, this file will still be treated as PHP, because you are including it in to a PHP script.
Generally with my file includes, I will use .inc.php, so the file name will look something like filename.inc.php. But it doesn't really matter what you use for your includes, as long as your main PHP script has a file name that ends with .php
callumd
01-06-2008, 09:27 AM
...
jamesm6162
01-06-2008, 10:16 AM
Thanks hey.
Oh and is there any specific reason you name your included files .inc.php?
I've seen that practice elsewhere and I was just wondering why.
callumd
01-06-2008, 11:40 AM
Ending an include file with .inc.php just makes it easier to identify as an include file. The reason I personally use it is because I saw it in a book once, and thought "Hey, I like that. I'm going to start doing it for my include files too".
This way, I will never mistake an include file for anything other than an include file.
jamesm6162
01-06-2008, 11:47 AM
Oh I see
Thanks for the help.
felgall
01-06-2008, 02:19 PM
If you configure your server to parse .inc files for PHP then naming them .inc doesn't matter (it just serves to distinguish between web pages and includes). If you don't configure it to do that and don't use .inc.php then the source code in the .inc can be read by anyone who finds out the filename.