在每个站点上设置PHP包含路径? [英] Setting PHP Include Path on a per site basis?

查看:110
本文介绍了在每个站点上设置PHP包含路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 php.ini 中设置PHP包含路径:

I can set the PHP include path in the php.ini:

include_path = /path/to/site/includes/

但其他网站受到影响所以这不好。

But then other websites are affected so that is no good.

我可以在每个文件的开头设置PHP include:

I can set the PHP include in the start of every file:

$path = '/path/to/site/includes/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

但这似乎是不好的做法,让事情变得混乱。

But that seems like bad practice and clutters things up.

所以我可以将其包含在内,然后将其包含在每个文件中:

So I can make an include of that and then include it into every file:

include 'includes/config.php';

include '../includes/config.php';

这就是我现在正在做的,但的包含路径config.php 将根据包含的内容而改变。

This is what I'm doing right now, but the include path of config.php will change depending on what is including it.

还有更好的方法吗?是否重要?

Is there a better way? Does it matter?

推荐答案

如果您使用apache作为网络服务器,您可以使用<覆盖(如果允许)设置em> .htaccess 文件。有关详细信息,请参阅 PHP手册

If you're using apache as a webserver you can override (if you allow it) settings using .htaccess files. See the PHP manual for details.

基本上你在你的网站根目录中放了一个名为 .htaccess 的文件,其中包含一些PHP ini 值。如果您将Apache配置为允许覆盖,则此站点将使用PHP配置中的所有值,+您在 .htaccess 文件中指定的值。

Basically you put a file called .htaccess in your website root, which contains some PHP ini values. Provided you configured Apache to allow overrides, this site will use all values in your PHP config, + the values you specify in the .htaccess file.

只能用于 PHP_INI_ALL PHP_INI_PERDIR 类型指令

如我链接的页面所述。如果您点击完整列表,您会看到包含路径是 PHP_INI_ALL 指令。

as stated in the page I linked. If you click through to the full listing, you see that the include path is a PHP_INI_ALL directive.

这篇关于在每个站点上设置PHP包含路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆