是否可以在不使用PHP .ini或.htaccess的情况下设置include_path,从而影响所有PHP目录?


Is it possible to set include_path without using php.ini or .htaccess, affecting all PHP directories?

在我的本地主机上,我修改php.ini来设置include_path。但是,随着时间的推移,php.ini中include_path的行变长了,看起来,嗯,很难看。我正在寻找一种方法来设置include_path,我可以复制粘贴一个包含行,说<?php include("superfile.php");?>在所有页面上,不管它们在目录树中的位置,其中superfile包含所有include_path指令。

我已经试过了,

<?php
    $include_path = $_SERVER["DOCUMENT_ROOT"] . "/more/directories/as/needed/";
    ini_set("include_path", $include_path);
    include("initialize.php");
?>

并将其保存为superfile.php的根文件夹。但是,如果我想设置驻留在root/sub的文件的包含路径,那么通过superfile.php,我需要执行<?php include("../superfile.php"); ?>(带有"directory up"点),这违背了我设置include_path的目的。

有什么建议吗?谢谢!

听起来您已经从php.ini中删除了所有自定义include_path指令。

要允许所有脚本调用<?php include("superfile.php");?>,只需在php.ini中添加一个允许调用include_path的条目,然后设置。