Forum Moderators: coopster

Message Too Old, No Replies

Safe includes outside of root

safe includes outside of root

         

ofie2

2:27 am on Aug 8, 2008 (gmt 0)

10+ Year Member



I'm looking to call variables from outside of the httpdocs folder to make the sensitive data more secure.

But everytime I try the script errors out. Is it possible that php 5 / Apache doesn't allow this?

I was able to find the sub folder by

$path = dirname(__FILE__);
$path = substr($path,0,strrpos($path,'httpdocs'));
$path = $path . 'private/info.php';

But if I try require, require_once, or include doesn't work.

This seems so simple, but after hours of working on the bigger project this seems to be kicking my butt.

Thanks for any help.

Ofie

eelixduppy

3:19 am on Aug 8, 2008 (gmt 0)



Maybe you have your include path set in your php.ini file? What are the errors that you are getting from the script?

jatar_k

1:39 pm on Aug 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



also try

echo $path;

maybe you're getting something unexpected into the var

as eelix said, what's the exact error?

ofie2

5:08 pm on Aug 8, 2008 (gmt 0)

10+ Year Member



Thank you both for your replies.

The errors are:

The show.php file is the one I'm using to view info.php file with variables.

PHP Warning: include() [<a href='function.include'>function.include</a>]: open_basedir restriction in effect. File(/var/www/vhosts/thedomain.com/private/info.php) is not within the allowed path(s): (/var/www/vhosts/thedomain.com/httpdocs:/tmp) in /var/www/vhosts/thedomain.com/httpdocs/TEST/show.php on line 6

PHP Warning: include(/var/www/vhosts/thedomain.com/private/info.php) [<a href='function.include'>function.include</a>]: failed to open stream: Operation not permitted in /var/www/vhosts/thedomain.com/httpdocs/TEST/show.php on line 6

PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '/var/www/vhosts/thedomain.com/private/info.php' for inclusion (include_path='.:') in /var/www/vhosts/thedomain.com/httpdocs/TEST/show.php on line 6

I echo'd the path I created and is displayed correctly.

Thanks,

Ofie

jatar_k

12:58 pm on Aug 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



this may shed some light
[php.net...]