What is an .inc and why use it?

后端 未结 8 683
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 21:49

I often see examples in PHP that include.inc files. What is the meaning of .inc? What it is used for? What are the disadvantages and advantages of using it?

相关标签:
8条回答
  • 2020-11-28 22:48

    It has no meaning, it is just a file extension. It is some people's convention to name files with a .inc extension if that file is designed to be included by other PHP files, but it is only convention.

    It does have a possible disadvantage which is that servers normally are not configured to parse .inc files as php, so if the file sits in your web root and your server is configured in the default way, a user could view your php source code in the .inc file by visiting the URL directly.

    Its only possible advantage is that it is easy to identify which files are used as includes. Although simply giving them a .php extension and placing them in an includes folder has the same effect without the disadvantage mentioned above.

    0 讨论(0)
  • 2020-11-28 22:49

    If you are concerned about the file's content being served rather than its output. You can use a double extension like: file.inc.php. It then serves the same purpose of helpfulness and maintainability.

    I normally have 2 php files for each page on my site:

    1. One named welcome.php in the root folder, containing all of the HTML markup.
    2. And another named welcome.inc.php in the inc folder, containing all PHP functions specific to the welcome.php page.

    EDIT: Another benefit of using the double extention .inc.php would be that any IDE can still recognise the file as PHP code.

    0 讨论(0)
提交回复
热议问题