共享主机 - 如何在 Web 根目录下包含 php 文件?

发布于 2024-12-08 21:12:00 字数 886 浏览 0 评论 0原文

我在尝试将文件包含到 php 脚本中时遇到问题。该文件存储在根文件夹中,该文件夹不是实际的 Web 根目录,而是我可以通过共享托管帐户访问的根目录。

我在此目录中创建了一个文件夹来存储 php 会话数据,与此相关的 .htaccess 配置将是以下行:

php_value session.save_path "/usr/home/accountname/sessions"

Web 根目录将存储在该目录中:

/usr/home/accountname/public_html/domainname/

我想要做的是保护保存数据库连接的 scipt详细信息,在一个类似这样的文件夹中:

/usr/home/accountname/includes/

这就是我当前包含该文件的方式:

require_once $_SERVER['DOCUMENT_ROOT'].'/includes/config.php';

我已经尝试过:

require_once $_SERVER['PATH'].'/usr/home/accountname/includes/config.php';

由于 $_SERVER['PATH'] 指向 /bin

当页面出现时,这不起作用空白,这意味着 config.php 中定义的变量未激活,因为该页面尚未包含在内。

任何人都可以提供有关此问题的一些信息,或者为我指出解决问题的方向。此外,任何有关此的教程或其他信息将不胜感激。

谢谢你!

I am having trouble trying to get a file to be included into a php script. This file is stored in the root folder, which is not the actual web root, but the root directory that I have access to via the shared hosting account.

I have created a folder in this directory that stores php session data, the .htaccess configuration regarding this would be the following line:

php_value session.save_path "/usr/home/accountname/sessions"

The web root would be stored in this directory:

/usr/home/accountname/public_html/domainname/

What I am trying to do is secure the scipt that holds database connection details, in a folder that would be something like this:

/usr/home/accountname/includes/

This is how i currently include the file:

require_once $_SERVER['DOCUMENT_ROOT'].'/includes/config.php';

I have tried this:

require_once $_SERVER['PATH'].'/usr/home/accountname/includes/config.php';

As $_SERVER['PATH'] points to /bin

This is not working as the page comes out blank, this would mean that the variables defined in config.php are not active as the page has not been included.

Could anyone provide some information regarding this matter, or point me in the direction of solving the problem. Also, any tutorials or other info regarding this would be greatly appreciated.

Thank you!

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

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

发布评论

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

评论(2

枉心 2024-12-15 21:12:01

如果包含 config.php 的脚本存储在您的 Web 根目录下,您可以写:

require_once dirname(__FILE__) . '/../../includes/config.php';

你已经尝试过了吗?

If the script including config.php is stored under your Web root, you can write:

require_once dirname(__FILE__) . '/../../includes/config.php';

Have you already tried?

把回忆走一遍 2024-12-15 21:12:01

如果您的脚本位于 /usr/home/accountname/public_html/domainname/something.php 中,您可以使用以下命令:

require_once(dirname(dirname(dirname(__FILE__))).PATH_SEPARATOR."includes".PATH_SEPARATOR."config.php");

If your script is in /usr/home/accountname/public_html/domainname/something.php, you could use this:

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