spires Posted May 20, 2010 Share Posted May 20, 2010 Hi. I have a website that i'm using to learn PHP OOP. To make my website more dynamic, I want to be able to place all include files into one php file 'initialize.php' But, I keep getting an error. initialize.php <?PHP defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR); defined('SITE_ROOT') ? null : define('SITE_ROOT', 'http://powtest.co.uk'.DS.'PHP_Training'.DS.'beyond_the_basics'.DS.'photogallery'); defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes'); require_once(LIB_PATH.DS."config.php"); require_once(LIB_PATH.DS."functions.php"); require_once(LIB_PATH.DS."session.php"); require_once(LIB_PATH.DS."database.php"); require_once(LIB_PATH.DS."user.php"); ?> index.php <?PHP require_once("../../includes/initialize.php"); if (!$session->is_logged_in()) { redirect_to('login2.php'); } $user = User::find_by_id($session->user_id); ?> PATH FOR INDEX.PHP: http://powtest.co.uk PHP_Training beyond_the_basics photogallery public admin index.php PATH FOR INITIALIZE.PHP: http://powtest.co.uk PHP_Training beyond_the_basics photogallery includes ERROR Warning: require_once() [function.require-once]: URL file-access is disabled in the server configuration in /home/p/o/powtest/web/public_html/PHP_Training/beyond_the_basics/photogallery/includes/initialize.php on line 7 Warning: require_once(http://powtest.co.uk/PHP_Training/beyond_the_basics/photogallery/includes/config.php) [function.require-once]: failed to open stream: no suitable wrapper could be found in /home/p/o/powtest/web/public_html/PHP_Training/beyond_the_basics/photogallery/includes/initialize.php on line 7 Fatal error: require_once() [function.require]: Failed opening required 'http://powtest.co.uk/PHP_Training/beyond_the_basics/photogallery/includes/config.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/p/o/powtest/web/public_html/PHP_Training/beyond_the_basics/photogallery/includes/initialize.php on line 7 This is probably something very easy, but I just can't seems to see it. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/202402-creating-a-path/ Share on other sites More sharing options...
premiso Posted May 20, 2010 Share Posted May 20, 2010 Your "SITE_ROOT" should be defined with $_SERVER['DOCUMENT_ROOT"] and not the web path. The webpath simply displays the file after processing. So most include files, which generalyl do not display data, will display nothing and thus include nothing. The DOCUMENT_ROOT is the path on the actual server, IE: /var/www/site.com/htdocs/ vs http://www.yourdomain.com/ But that is not the problem, the problem is you are using a relative path to locate the intiialize.php I would use the absolute path instead: require_once($_SERVER['DOCUMENT_ROOT'] . "/PHP_Training/beyond_the_basics/photogallery/includes/initialize.php"); Given that intialize.php is in the root directory should work on all pages. To fix your SITE_ROOT declaration: defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'] . DS .'PHP_Training'.DS.'beyond_the_basics'.DS.'photogallery'); This will provide the actual location and not the web location so it accesses the actual file and not the webversion. Quote Link to comment https://forums.phpfreaks.com/topic/202402-creating-a-path/#findComment-1061212 Share on other sites More sharing options...
spires Posted May 20, 2010 Author Share Posted May 20, 2010 Hi, Thanks for your help, Glad I asked now, I never would nave seen that There is however, a new bug that has been thrown up: Warning: require_once(/htdocs/PHP_Training/beyond_the_basics/photogallery/includes/initialize.php) [function.require-once]: failed to open stream: No such file or directory in /home/p/o/powtest/web/public_html/PHP_Training/beyond_the_basics/photogallery/public/admin/index2.php on line 2 Fatal error: require_once() [function.require]: Failed opening required '/htdocs/PHP_Training/beyond_the_basics/photogallery/includes/initialize.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/p/o/powtest/web/public_html/PHP_Training/beyond_the_basics/photogallery/public/admin/index2.php on line 2 It looks like it's to do with: require_once($_SERVER['DOCUMENT_ROOT'] . "/PHP_Training/beyond_the_basics/photogallery/includes/initialize.php"); any other pointers would be very helpfull Thanks Quote Link to comment https://forums.phpfreaks.com/topic/202402-creating-a-path/#findComment-1061220 Share on other sites More sharing options...
premiso Posted May 20, 2010 Share Posted May 20, 2010 Something is weird about your server. By all means that I know $_SERVER['DOCUMENT_ROOT'] should point to: /home/p/o/powtest/web/public_html/ Not "htdocs". Is htdocs set as a symbolic link? Are you on a shared server or VPS or your own? If your own / VPS, you should be able to fix this in the vhosts file, but yea. I do not know what the reasoning it is set to htdocs and thus cannot help effectively. Quote Link to comment https://forums.phpfreaks.com/topic/202402-creating-a-path/#findComment-1061223 Share on other sites More sharing options...
spires Posted May 20, 2010 Author Share Posted May 20, 2010 I'm on a dedicated server. Ok, well thanks for all your help with this, at least i'm moving in the right direction now Cheers Quote Link to comment https://forums.phpfreaks.com/topic/202402-creating-a-path/#findComment-1061226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.