php 什么是 .inc,为什么要使用它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7129842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:05:25  来源:igfitidea点击:

What is an .inc and why use it?

php

提问by dpp

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?

我经常在 PHP 中看到包含.inc 文件的示例。.inc 是什么意思?它是用来做什么的?使用它的缺点和优点是什么?

回答by Paul

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.

它没有任何意义,它只是一个文件扩展名。如果文件被设计为包含在其他 PHP 文件中,那么某些人会使用 .inc 扩展名命名文件,但这只是约定。

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.

它确实有一个可能的缺点,即服务器通常未配置为将 .inc 文件解析为 php,因此如果该文件位于您的 web 根目录中并且您的服务器以默认方式配置,则用户可以查看您的 php 源代码通过直接访问 URL 来访问 .inc 文件。

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.

它唯一可能的优点是很容易识别哪些文件被用作包含。尽管简单地给它们一个 .php 扩展名并将它们放在一个包含文件夹中具有相同的效果,但没有上述缺点。

回答by Wasted_Coder

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.

如果您担心所提供的文件内容而不是其输出。您可以使用双扩展名,例如:file.inc.php. 然后它服务于有用性和可维护性的相同目的。

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

我网站上的每个页面通常都有 2 个 php 文件:

  1. One named welcome.phpin the root folder, containing all of the HTML markup.
  2. And another named welcome.inc.phpin the incfolder, containing all PHP functions specific to the welcome.phppage.
  1. 一个welcome.php在根文件夹中命名的,包含所有的 HTML 标记。
  2. 另一个welcome.inc.phpinc文件夹中命名,包含特定于welcome.php页面的所有 PHP 函数。

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

编辑:使用双扩展的另一个好处.inc.php是任何 IDE 仍然可以将文件识别为 PHP 代码。

回答by Devraj

Generally means that its a file that needs to be included and does not make standalone script in itself.

通常意味着它是一个需要包含的文件,并且本身不制作独立脚本。

This is a convention not a programming technique.

这是约定而不是编程技术。

Although if your web server is not configured properly it could expose files with extensions like .inc.

尽管如果您的 Web 服务器配置不正确,它可能会暴露带有 .inc 等扩展名的文件。

回答by karim79

It's just a way for the developer to be able to easily identify files which are meant to be used as includes. It's a popular convention. It does not have any special meaningto PHP, and won't change the behaviour of PHP or the script itself.

这只是开发人员能够轻松识别要用作包含的文件的一种方式。这是一个流行的约定。它对PHP没有任何特殊意义,不会改变 PHP 或脚本本身的行为。

回答by Awais Qarni

This is a convention that programmer usually use to identify different file names for include files. So that if the other developers is working on their code, he can easily identify why this file is there and what is purpose of this file by just seeing the name of the file.

这是程序员通常用来标识包含文件的不同文件名的约定。这样,如果其他开发人员正在处理他们的代码,他就可以通过查看文件名轻松识别为什么该文件存在以及该文件的用途是什么。

回答by dpp

Just to add. Another disadvantage would be, .inc files are not recognized by IDE thus, you could not take advantage of auto-complete or code prediction features.

只是为了补充。另一个缺点是,IDE 无法识别 .inc 文件,因此您无法利用自动完成或代码预测功能。

回答by Robert Ross

In my opinion, these were used as a way to quickly find include files when developing. Really these have been made obsolete with conventions and framework designs.

在我看来,这些被用作在开发时快速找到包含文件的一种方式。实际上,这些已经被惯例和框架设计淘汰了。

回答by Mwiza

Note that You can configure Apache so that all files With .incextension are forbidden to be retrieved by visiting URL directly.

请注意,您可以配置Apache,.inc禁止直接访问URL 检索所有带有扩展名的文件。

see link:https://serverfault.com/questions/22577/how-to-deny-the-web-access-to-some-files

见链接:https: //serverfault.com/questions/22577/how-to-deny-the-web-access-to-some-files