I’ve built a very simple website using PHP Includes to display the footer and sidebar, these PHP includes work when I’m on my computer and view them using EasyPHP, however when I come to upload the site and view it I get the following error displayed on page:
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, hosted for free on 000webhost.
Here’s an example of an include on index.php, used to display the sidebar inside my “includes” folder:
<?php include $_SERVER['DOCUMENT_ROOT'] . "/includes/sidebar.php"; ?>
I’m using the DOCUMENT_ROOT instead of a normal include because some pages are embedded in deeper directories, and the includes will become dead links.
I am guessing since it will be shared hosting it may be set to you’re webroot…
So simply include using:
To expand on that a bit… Hosting Providers usually set open_basedir for security reasons (http://www.php.net/manual/en/ini.core.php#ini.open-basedir)