PHP 在 EasyPHP 下包含良好的开发工作,但在上传到主机时则不然


PHP includes work fine in development under EasyPHP, but not when uploaded to host

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

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

这是该网站,免费托管在000webhost上。

下面是一个包含索引.php的示例,用于在我的"include"文件夹中显示侧边栏:

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

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

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

因此,只需包括使用:

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

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

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

是的,

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

我的包含现在看起来像这样:

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

其中 *s 是您的主根。