xc0n Posted July 31, 2011 Share Posted July 31, 2011 Ok so i want to stop my config file from being accessed directly through a browser, the best way to do this is to not have config.php in my public_html folder, that way i can include it in a file but its not accessible directly. eg below: /home/esecure/public_html/index.php /home/esecure/hidden_files/config.php now index.php requires config.php to run so ive used the codes: <?php require($_SERVER['DOCUMENT_ROOT'] . '/../hidden_files/config.php'); ?> But it wont work. It wont go back past public_html folder i just get an error. Warning: require(/home/esecure/public_html/../config.php) [function.require]: failed to open stream: No such file or directory in /home/esecure/public_html/config.php on line 13 The code below works, but i dont want to link to config this way i want the above way to work. What am i missing? <?php require '/home/esecure/hidden_files/config.php' ?> thanks in advance Link to comment https://forums.phpfreaks.com/topic/243352-_serverdocument_root-wont-go-back-levels/ Share on other sites More sharing options...
inversesoft123 Posted July 31, 2011 Share Posted July 31, 2011 include($_SERVER['DOCUMENT_ROOT'].'/hidden_files/config.php'); or use "require" Link to comment https://forums.phpfreaks.com/topic/243352-_serverdocument_root-wont-go-back-levels/#findComment-1249695 Share on other sites More sharing options...
xc0n Posted July 31, 2011 Author Share Posted July 31, 2011 index.php runs include($_SERVER['DOCUMENT_ROOT'].'/hidden_files/config.php'); but index.php in in the public_html folder so the code you gave me aboce will be looking in /home/user/public_html/hidden_files instead of /home/user/hidden_files any other ideas? Link to comment https://forums.phpfreaks.com/topic/243352-_serverdocument_root-wont-go-back-levels/#findComment-1249697 Share on other sites More sharing options...
inversesoft123 Posted July 31, 2011 Share Posted July 31, 2011 okay i got it now, use php or htaccess or ini file to set default include path.. on single page by using php you can do somthing lke this. http://www.geeksengine.com/article/php-include-path.html Link to comment https://forums.phpfreaks.com/topic/243352-_serverdocument_root-wont-go-back-levels/#findComment-1249701 Share on other sites More sharing options...
xc0n Posted July 31, 2011 Author Share Posted July 31, 2011 ok kool ill have a look thanks, any idea why code below doesnt work anyone? <?php require($_SERVER['DOCUMENT_ROOT'] . '/../hidden_files/config.php'); ?> Link to comment https://forums.phpfreaks.com/topic/243352-_serverdocument_root-wont-go-back-levels/#findComment-1249705 Share on other sites More sharing options...
xc0n Posted July 31, 2011 Author Share Posted July 31, 2011 ok i figured it out i used the code below: <?php define('ABSPATH',dirname(dirname(__FILE__)) . '/'); require(ABSPATH . 'hidden_files/config.php'); ?> Link to comment https://forums.phpfreaks.com/topic/243352-_serverdocument_root-wont-go-back-levels/#findComment-1249711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.