相对包括移动到IIS后不再工作?

时间:2009-12-01 10:49:12

标签: php include

好的,我在这里看到了很多关于php include()指令的抱怨。这似乎也成了我悲伤的原因。

我的网站结构是这样的:

public_html\index.php
public_html\includes\content.inc.php
public_html\language\en\language.inc.php
public_html\classes\db.inc.php

该网站在Apache上没有任何问题。但它不适用于IIS(grr ......#@ !!!%)。

让我解释一下: 所做的是 index.php 始终由webbrowser调用,并且根据请求,它包括 content.inc.php (这些内容文件中有许多和index.php包括基于逻辑的适当的一个

// -- index.php --
include(includes/content.inc.php);

到目前为止,它在Apache和IIS上运行良好。

现在 content.inc.php 又包含 lang.inc.php db.inc.php

看起来像:

// -- content.inc.php --
include(language/en/language.inc.php)
include(classes/db.inc.php)

这些行在Apache上运行良好,但IIS抱怨它无法归档要包含的文件。

为什么呢?因为Apache维护当前文件夹“。”是public_html\脚本执行首先开始的地方。 另一方面,IIS改变了“。”的含义。成为当前正在处理的文件。即在包含content.inc.php之后,IIS解释“。”为public_html\includes\

现在我知道一种解决方案是以某种方式将所有包含路径更改为绝对路径。但我的问题是,这是否真的是我理解的Apache / IIS问题?是否有IIS或PHP设置使其正常运行而不会在代码中出现问题?

BTW,PHP.ini有

include_path=".;C:\PHP\PEAR"

2 个答案:

答案 0 :(得分:2)

您的包含文件应该完全位于您的public_html树的外部。

// Your setup should resemble:

/public_html/index.php
/includes/
/include/languages
/include/classes

// If on your phsical drives, they equate to;

c:/wwwroot/public_html/index.php
c:/wwwroot/includes/
c:/wwwroot/includes/languages
c:/wwwroot/includes/classes

然后,您的PHP.INI文件中的设置应更改为:

include_path =“.; C \ PHP \ PEAR; C:\ wwwroot \ includes”

我猜猜像wwwroot这样的内容是你输入html的目录,必要时进行更改。

重新启动IIS服务以获取新的ini设置。

echo ini_get('include_path') ; 

保持理智......

现在PHP将始终在wwwroot / includes中查找包含文件,因此您可以通过执行此操作来包含/ languages之类的内容;

include 'language/eng/language.inc.php' ;

这就是你想要的。

答案 1 :(得分:0)

我通常喜欢从服务器的根目录中添加include '/includes/language.inc.php'。这样,它将在您的站点结构中的任何文件夹中工作。我也以这种方式链接我的所有CSS和JavaScript,当你有来自不同文件夹结构的文件调用它们时,可以更容易地将东西放入包含文件中。

相关问题