共享主机 - 如何在 Web 根目录下包含 php 文件?
我在尝试将文件包含到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果包含 config.php 的脚本存储在您的 Web 根目录下,您可以写:
你已经尝试过了吗?
If the script including config.php is stored under your Web root, you can write:
Have you already tried?
如果您的脚本位于
/usr/home/accountname/public_html/domainname/something.php
中,您可以使用以下命令:If your script is in
/usr/home/accountname/public_html/domainname/something.php
, you could use this: