【问题标题】:PHP includes work fine in development under EasyPHP, but not when uploaded to hostPHP 在 EasyPHP 下的开发中可以正常工作,但在上传到主机时不能正常工作
【发布时间】:2012-06-18 20:45:16
【问题描述】:

我使用 PHP Includes 构建了一个非常简单的网站来显示页脚和侧边栏,当我在计算机上并使用 EasyPHP 查看它们时,这些 PHP 包括工作,但是当我上传网站并查看它时,我在页面上显示以下错误:

Warning: include() [function.include]: open_basedir restriction in effect.
File(/usr/local/apache/htdocs/includes/sidebar.php) is not within the allowed path(s):
(/home/:/usr/lib/php:/tmp) in /home/a5562725/public_html/index.php on line 26

Here's the site, 在 000webhost 上免费托管。

这是 index.php 中包含的示例,用于在我的“包含”文件夹中显示侧边栏:

    <?php include $_SERVER['DOCUMENT_ROOT'] . "/includes/sidebar.php"; ?> 

我正在使用 DOCUMENT_ROOT 而不是普通的包含,因为某些页面嵌入在更深的目录中,并且包含将成为死链接。

【问题讨论】:

  • 可能是权限问题。确保 apache 用户能够打开 sidebar.php。如果不确定,请将 /includes/sidebar.php 设置为具有 755 权限。

标签: php html


【解决方案1】:

我猜因为它将是共享主机,它可能设置为您的 webroot...

所以简单地包括使用:

<?php include "/includes/sidebar.php"; ?>

进一步扩展...托管服务提供商通常出于安全原因设置 open_basedir (http://www.php.net/manual/en/ini.core.php#ini.open-basedir)

【讨论】:

  • 感谢您的回答,我现在收到以下错误:警告:include() [function.include]: Failed opening '/includes/sidebar.php' for include (include_path='.:/ usr/lib/php:/usr/local/lib/php') 在第 26 行的 /home/a5562725/public_html/index.php 你可以在marcuslywood.co.uk查看它自己
  • OK 试试
  • 谢谢!这适用于顶级页面,但是,正如问题中所述,我在较低的目录中有一些文件也需要这些文件,我认为我应该在路径之前使用普通的“../”目录,就像在 HTML 和 CSS 中一样?谢谢!
  • 太棒了,简直不敢相信就这么简单哈哈!非常感谢!
【解决方案2】:

这种情况总是会发生,只要我提出问题,我就会找到解决方案!

是的,问题似乎与共享主机有关,我必须指向主机的主根目录才能使其工作,对于 000webhost 用户,您可以在控制面板的右侧找到它。

我的包含现在如下所示:

<?php include('/home/a********/public_html/includes/sidebar.php'); ?>

*s 是您的主根目录。

【讨论】:

  • 您最好使用 Brian 的建议,因为您不需要根据您部署代码的位置不断更改此路径。
猜你喜欢
  • 2017-12-12
  • 1970-01-01
  • 2018-03-07
  • 2013-06-29
  • 1970-01-01
  • 2012-07-26
  • 2018-05-29
  • 1970-01-01
  • 2021-11-23
相关资源
最近更新 更多