更改 include_path 或在每个 php 文件前面添加

发布于 2024-10-03 19:38:09 字数 839 浏览 1 评论 0原文

我有一个应用程序,它将一些数据存储在 /library/ 目录中的 .php 文件中, 例如。 /library/config.php

在我的旧主机上,library 位于包含路径中,因此我可以在任何地方执行 require('config.php') 而无需提供真实路径。

是否有机会自动添加每个 .php 文件以更新包含路径?

有一些情况:

  • 应用程序不遵循前端控制器模式
  • 我无法访问 php.ini
  • 我无法直接访问 include_path 中已存在的任何目录
  • I无法使用 php_flag include_path
  • 我无法使用 php_flag auto_prepend_file
  • 一些 .php 文件在 .htaccess 中有自己的规则

除了 < code>ctrl+H 并将 替换为

编辑:

我正在寻找类似于:

RewriteCond %{REQUEST_FILENAME}  !-F
RewriteCond %{REQUEST_FILENAME}  !-d
RewriteRule (^*\.php)$ /library/$1 [NC,L]

I have an app which stores some data in .php files in /library/ directory,
eg. /library/config.php.

On my old hosting library was in the include path, so I was able do do require('config.php') anywhere without providing the real path.

Is there any chance to auto prepend each .php file, to update the include path?

There are some circumstances:

  • the app does not follow front controller pattern
  • I have no access to php.ini
  • I have no direct access to any of the dirs already present in include_path
  • I can't use php_flag include_path
  • I can't use php_flag auto_prepend_file
  • some .php files have their own rules in .htaccess

Any other way than ctrl+H and replace <? with <? set_include_path…?

Edit:

What I am looking for would be something similar to:

RewriteCond %{REQUEST_FILENAME}  !-F
RewriteCond %{REQUEST_FILENAME}  !-d
RewriteRule (^*\.php)$ /library/$1 [NC,L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮是我掰弯的 2024-10-10 19:38:09

在需要调整库文件的文件顶部添加 set_include_path()运行时的包含路径(无需触及 php.ini 或 .htaccess 文件)。

set_include_path(dirname(__FILE__).'/library'.PATH_SEPARATOR.get_include_path());

这会将您的库路径添加到当前包含路径之前,并使那里的文件直接可用。您需要调整 '/library' 以匹配您的库路径(相对于当前文件的位置)。

Add set_include_path() at the top of the file where you need the library files to adjust the include path at runtime (no need to touch php.ini or .htaccess files).

set_include_path(dirname(__FILE__).'/library'.PATH_SEPARATOR.get_include_path());

This prepends your library path to the current include path and makes the files there directly available. You need to adjust '/library' to match your library path (relative to the current file's location).

话少心凉 2024-10-10 19:38:09

ini_set() 也被禁止吗?这也允许您修改 include_path

Is ini_set() forbidden too? Which allows you to modify the include_path too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文