open_basedir restriction in effect. help?

werezwolf

New Member
Messages
8
Reaction score
0
Points
0
hi all heres a problem i cant understand

Site Structure: (only showing part of the structure)
WWW/
Config/ (755)
config.php (644)
functions.php (644)​
index.php (644)​
------------------------------
the file works fine on my home test server but here it through up this.

Warning: require_once() [function.require-once]: open_basedir restriction in effect. File(/../Config/functions.php) is not within the allowed path(s): (/home/:/tmp) in /home/werezwol/public_html/Config/Config.php on line 21

Warning: require_once(/../Config/functions.php) [function.require-once]: failed to open stream: Operation not permitted in /home/werezwol/public_html/Config/Config.php on line 21

Fatal error: require_once() [function.require]: Failed opening required '/../Config/functions.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/werezwol/public_html/Config/Config.php on line 21

--------------------------------

The nice line of code behind it. As you can guess yes this is the backbone file of my site nothing works without this.
PHP:
<?php
//THIS IS CONFIG.PHP
    //Define Site Name
    $site = 'The Site';
    $style = 'DarkFantasy'; // Warning: Changing the style set may alter site layout in unwanted ways.
    
    //------ Do Not Change Below ------//
    
    //Define DIR Listings - absolute path
    define('MAINDIR',"/.."); // this goes from /config/config.php to / or full path as /config/../
        define('Config_DIR',MAINDIR . '/Config'); // full path as /config/../config/
            define('Config_img_Dir',Config_DIR . '/images');
        define('BB_DIR',MAINDIR . '/bb');
            define('BB_style',BB_DIR . "/styles/$style");
                define('BB_theme',BB_style . '/theme/images');
                define('BB_imgset',BB_style . '/imageset/en');
    
    //Define Var
    define('SITE',$site);
    
    //Require Variables, Functions & Template
    require_once(Config_DIR . '/functions.php');
    require_once(Config_DIR . '/template.php');

?>
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
The leading slash means the MAINDIR path is absolute. The root directory is its own parent, so '/..' is equivalent to '/', which means Config_DIR is '/Config', BB_DIR is '/BB' &c. All of these are outside the '/home' and '/tmp' branches (not to mention non-existent) and thus blocked by the open_basedir restriction. To resolve, remove the leading slash or (more correctly) set MAINDIR to $_SERVER['DOCUMENT_ROOT'].
 

werezwolf

New Member
Messages
8
Reaction score
0
Points
0
/.. is the directory up yes?. the config.php file isen't on the root dir but in the folder /config/. so it should work.

i did post my sites structure up using tab indenting to simulate tree structure with current file permissions ive also added more comments to code above to show this.

Site Structure:
(only showing part of the structure)
WWW/ ( /home/werezwol/public_html/ aka root dir)
Config/ (755)
config.php (644)
functions.php (644)​
index.php (644)​
im also receiving errors apart from index.php any other files on it don't exist at all. all files have the default permissions of 644 and reside on root dir like the index.php (the links work on my local server)

also my links use this absolute path to all links correct go to its destination when i use $_SERVER['DOCUMENT_ROOT'] things get messed up example www.name.exofire.com/home/werezwol/public_html/index.php. using my path it goes to www.name.exofire.com/index.php

www.name.exofire.com is an example site

as i have said i have tested this tree structure and it correctly displays and imported it all via a zip file all structural integrity has not been changed.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Funny. You asked a question.
You were given an answer by one of the most knowledgeable posters on this forum.
But since it wasn't the answer you wanted, you didn't even bother to try his solution?
Why ask?

If you don't believe that the leading slash is a problem on a Linux box, put this scriptlet in Config and run it from the server.

PHP:
<?php

$path_slash = '/../Config/functions.php'  ;
$path_slashless = '../Config/functions.php'  ;

echo "With slash : " ;

echo realpath(  $path_slash  );

echo "  <-<br />\n" ;

echo "Without slash : " ;

echo realpath(  $path_slashless  );

?>
 

werezwolf

New Member
Messages
8
Reaction score
0
Points
0
if i do that i get the following:

Warning
: require_once(../Config/functions.php) [function.require-once]: failed to open stream: No such file or directory in /home/werezwol/public_html/Config/Config.php on line 22

Fatal error: require_once() [function.require]: Failed opening required '../Config/functions.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/werezwol/public_html/Config/Config.php on line 22

this error also occurs on my local server thats why i added the / in front. i would of posted the result of your test debug code but i cant access any files other then my index.php on the root (permissions still have not been changed.) since i receive:

The page you requested is not available, please try again in a few minutes. Alternatively you can use the form below to find what you are looking for.
Registering an account with us is easy and free, sign up today!

i appreciate the help but im just clearing things up and kinda disappointed that i could not just export it on to the server with out problems. the error above may have something to do with it i'm not sure. could anyone direct me to a permissions explanation page i need to find out why some files apparently don't exist.
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
/.. is the directory up yes?.
No. Each directory has a ".." entry, which refers to the parent of that directory, except in the root directory where it refers to the root directory. If a path begins with "..", such as in "../Config", it's the parent of the current directory. In "/home/werezwol/public_html/bb/../Config", ".." refers to the parent of "bb", which is "public_html"; thus the path is equivalent to the canonical path "/home/werezwol/public_html/Config". In "/../Config", ".." is the parent of "/", which is the root directory; thus the path is equivalent to "/Config", which doesn't exist on the X10 servers.

Setting MAINDIR to "/.." is definitely wrong. Setting it to ".." is mostly wrong, because it will only work in subdirectories of the doc root. It won't work in the doc root and it won't work in descendants of subdirectories of the doc root.

the config.php file isen't on the root dir but in the folder /config/. so it should work.
The file path "/config" doesn't exist, an neither does "/Config" (the various versions of extfs, the primary file systems used under Linux, are case sensitive).

/home/werezwol/public_html/ aka root dir
No. "/home/werezwol/public_html/" is the document root for your site. The root directory has the absolute path "/".

also my links use this absolute path to all links correct go to its destination when i use $_SERVER['DOCUMENT_ROOT'] things get messed up example www.name.exofire.com/home/werezwol/public_html/index.php.
Then you're mixing filesystem paths with URL paths. URLs and filesystems are different namespaces. MAINDIR can only refer to a path in one of these namespaces. include, require, include_once and require_once, as well as many other server side functions, use filesystem paths. virtual and anything client side, such as links, use URL paths.

Since functions.php and template.php are in the same directory as Config.php, don't bother prefixing either with a path.
PHP:
// Config.php
...
require_once('functions.php');
require_once('template.php');
 
Last edited:

werezwolf

New Member
Messages
8
Reaction score
0
Points
0
Ah i see now.

Thanks for that. still using the /.. for links only it works because its relative from config.php. Also thanks for saying that everything case sensitive fixed most of my problems. could there be anyway i can set my local server to use absolute file paths instead. using Wamp install has Apache 2.2.11 and PHP 3.5.

now i just got to go through my CSS ><

anyway this problems is
RESOLVED

Thank you all
 
Top