bpops Posted February 4, 2008 Share Posted February 4, 2008 I have a very strange problem. I have a directory structure such as this: /web/ /web/forum/ /web/test/ Under '/web/' I have a php file (top.php) that I include in every page that signs people into the forum automatically. To access the forum, though, there's an include in top.php. i.e. <?php // top.php include('../forum/forum.php'); ?> When I include top.php in a file under '/web' it goes like this: <?php // index.php include('top.php'); ?> This all works fine. The problem arises when I have a file under '/web/test/.' I include top.php via <?php // /web/test/index.php include('../top.php'); ?> It grabs top.php just fine, but since IN top.php, the path to the forums is '../forum/' and not '../../forum/', I get an error. Is there an easy way to fix this still using my single top.php file? Are there any root directory commands or something? Quote Link to comment https://forums.phpfreaks.com/topic/89422-solved-question-about-paths-for-multiple-includes/ Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 Try this out: <?php // top.php $include_base = dirname(__FILE__); include($include_base.'/forum/forum.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89422-solved-question-about-paths-for-multiple-includes/#findComment-457906 Share on other sites More sharing options...
bpops Posted February 4, 2008 Author Share Posted February 4, 2008 Thanks for the reply, rhodesa. I tried it and it did not work, but it's my mistake. I realized in my original post, I should have written that the directories are: /web/ /forum/ /web/test/ (/forum is not under /web/) Quote Link to comment https://forums.phpfreaks.com/topic/89422-solved-question-about-paths-for-multiple-includes/#findComment-457912 Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 well...then decide what you want your base to be. I'm going to make a decision and set the 'include base' to be the root of all this stuff. <?php // /web/top.php $include_base = dirname(dirname(__FILE__)); include($include_base.'/forum/forum.php'); ?> <?php // /web/index.php include('top.php'); ?> <?php // /web/test/index.php include('../top.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89422-solved-question-about-paths-for-multiple-includes/#findComment-457919 Share on other sites More sharing options...
bpops Posted February 4, 2008 Author Share Posted February 4, 2008 Rhodesa, That works beautifully, thank you!!! Quote Link to comment https://forums.phpfreaks.com/topic/89422-solved-question-about-paths-for-multiple-includes/#findComment-457922 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.