Texan78 Posted August 18, 2016 Share Posted August 18, 2016 I am having some problems with an include statement. Seems like a very simple task but, for some reason probably due to lack of knowledge it isn't working. Here is the layout of the folder structure I am working with for example. The pages are in a sub-domain. Sub-domain is called media. The index page is in media > network > kdfw > index.php The index.php is the file in which I am trying to include the file in. The included file is in media > network > kdfw > inc These are the methods I have tried... <?php include '/media/inc/chaserData.php'; ?> <?php include 'media/inc/chaserData.php'; ?> <?php include '/inc/chaserData.php'; ?> <?php include 'inc/chaserData.php'; ?> <?php include ($_SERVER['DOCUMENT_ROOT'].'/media/inc/chaserData.php'); ?> <?php include ($_SERVER['DOCUMENT_ROOT'].'media/inc/chaserData.php'); ?> <?php include ($_SERVER['DOCUMENT_ROOT'].'/inc/chaserData.php'); ?> <?php include ($_SERVER['DOCUMENT_ROOT'].'inc/chaserData.php'); ?> None of the above work and I am not sure as to why. Is there anyone who could provide some insight and shed some light to this issue? -Thanks Quote Link to comment https://forums.phpfreaks.com/topic/301929-problem-with-include-statement/ Share on other sites More sharing options...
Yohanne Posted August 18, 2016 Share Posted August 18, 2016 <?php include '../inc/chaserData.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/301929-problem-with-include-statement/#findComment-1536288 Share on other sites More sharing options...
Texan78 Posted August 18, 2016 Author Share Posted August 18, 2016 Thanks, I have tried that too with my many combinations. That does not work ether. This is the error I get in the error log trying the above suggestion. I am not sure if this is because it is in a sub-domain or what but I am having all kinds of trouble using include statements. Even in my dbinfo.php file I use in my script that calls data from a MySQL I had issues and had to use ($_SERVER['DOCUMENT_ROOT'] before that include statement to even get that to work. Anyways, here is the error from using the suggestion you mentioned. [17-Aug-2016 22:54:02] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '../inc/chaserData.php' for inclusion (include_path='.:/usr/lib64/php:/usr/share/pear') in /home2/livestp1/public_html/media/network/kdfw/index.php on line 40 Quote Link to comment https://forums.phpfreaks.com/topic/301929-problem-with-include-statement/#findComment-1536289 Share on other sites More sharing options...
Solution Texan78 Posted August 18, 2016 Author Solution Share Posted August 18, 2016 I got it sorted out by using this below. I am not sure if this is the correct method but, it works. I think because it is an addon domain and the files are in a sub-domain of the add on domain the normal method doesn't work as normal I am assuming. <?php include($_SERVER['DOCUMENT_ROOT'].'/network/kdfw/inc/chaserData.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/301929-problem-with-include-statement/#findComment-1536290 Share on other sites More sharing options...
requinix Posted August 18, 2016 Share Posted August 18, 2016 The DOCUMENT_ROOT method is the best method. Remember that it starts at the root of your website (which is apparently "media"), not the current directory. Using __DIR__ is the second best method and is relative to the current directory. include(__DIR__ . "/inc/chaserData.php"); Quote Link to comment https://forums.phpfreaks.com/topic/301929-problem-with-include-statement/#findComment-1536292 Share on other sites More sharing options...
ginerjm Posted August 18, 2016 Share Posted August 18, 2016 An added note: You don't have to bracket your includes EACH with a php start and end tag. One pair will do it. <?php include.... include..... include.... (more includes) more php lines and more and more ?> Quote Link to comment https://forums.phpfreaks.com/topic/301929-problem-with-include-statement/#findComment-1536298 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.