port80 Posted May 15, 2013 Share Posted May 15, 2013 Thank you for your time. I am not sure where this really belongs the HTML, CSS, Application Design or one of the PHP topics. So I figured I would post here. In my search I have found topics that come close to my question but have not provided a fix for my issue. So I'm asking for help. That and I am a beggining Web Developer. Problem: the php includes I use are not displayed on web pages in subdirectories. If I add ../ to the php include so it is like this: <?php include ("../menu.php"); ?> on the newpage.php only some of the included files are shown on the page in the subdirectory. All links on the file newpage.php now act as though they were written <a href="../menu.php">link</a> and don't work. They are acctually written <a href="menu.php">link</a>. Directory & Files / index.php header.php footer.php menu.php <!-- contains all links for site --> style.css subdir/ newpage.php newpage.php include code <div id="links"><?php include ("menu.php");?></div> Question? How do I fix it so that the menu.php and other included files are shown on the subdir pages? How do I make the links properly reflect the location. Since absolute or relative pathing appears to muck it up. FYI: I do not have CLI access to the server. Only ftp access. Thanks again for any help you may provide. Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/ Share on other sites More sharing options...
Solution requinix Posted May 15, 2013 Solution Share Posted May 15, 2013 If the problem is that the include()s are simply not working then you need to use absolute paths when giving filenames: "menu.php" alone isn't enough. include ($_SERVER["DOCUMENT_ROOT"] . "/menu.php");If the problem is the links lead to 404s then you need to use absolute paths when giving URLs: "menu.php" alone isn't enough. Menu Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/#findComment-1430253 Share on other sites More sharing options...
port80 Posted May 16, 2013 Author Share Posted May 16, 2013 If the problem is that the include()s are simply not working then you need to use absolute paths when giving filenames: "menu.php" alone isn't enough. include ($_SERVER["DOCUMENT_ROOT"] . "/menu.php");If the problem is the links lead to 404s then you need to use absolute paths when giving URLs: "menu.php" alone isn't enough. <a href="/menu.php">Menu</a> Thank yo for your responce. They are not getting 404 errors. The included files are just not showing up. I will give the $_SERVER["DOCUMENT_ROOT"] a try. I did not correctly interpret the use of $_SERVER["DOCUMENT_ROOT"]. I thought it was a setting in the PHP ini file that was set. Not something to be used in coding. Thanks again, I'll post back the status Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/#findComment-1430337 Share on other sites More sharing options...
port80 Posted May 16, 2013 Author Share Posted May 16, 2013 Thank you requinix for responding. I have tried these iterations and it is still not working. I just figured I would run through multiple posabilities. 1st attempt: <div id="links"><?php include ($_SERVER["DOCUMENT_ROOT"] . "menu.php");?></div> 2cnd attempt: <div id="links"><?php include ($_SERVER["DOCUMENT_ROOT"] . "/menu.php");?></div> 3rd attempt: <div id="links"><?php include ($_SERVER["../"] . "/menu.php");?></div> Though, if I understand it correctly it should be as you typed "DOCUMENT_ROOT". I was just trying ideas to see if it wold change anything. 4th attemp: <div id="links"><?php include ($_SERVER["DOCUMENT_ROOT"] . "/menu.php"); ?></div> 5th attemp: <div id="links"><?php include ($_SERVER["DOCUMENT_ROOT"] . "serverip/menu.php");?></div> 6th attemp: <div id="links"><?php include ("serverip/menu.php");?></div> Am I missing something here? Everyting works for the directories above the subdir/ folder. The css works for the subdir/newpage.php. The included header, footer and menu pages are not showing for the subdir/newpage.php. Permissions are 755 or rwxr-xr-x for the subdir/ and files in the subdir/ Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/#findComment-1430390 Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 Well, go to newpage.php file and give us the result of: // current directory echo getcwd() . "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/#findComment-1430478 Share on other sites More sharing options...
port80 Posted May 17, 2013 Author Share Posted May 17, 2013 It gives the path /var/www/html/dd/subdir I tried using thse a couple hours after my last post. They did not work either. <div id="links"><?php include ("serverip/var/www/html/dd/menu.php");?></div> And <div id="links"><?php include ("/var/www/html/dd/menu.php");?></div> Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/#findComment-1430593 Share on other sites More sharing options...
port80 Posted May 17, 2013 Author Share Posted May 17, 2013 The server just had updates applied. using <?php include ("../menu.php"); ?> works now when it did not before. I would rather the $_SERVER["DOCUMENT_ROOT"] would work. For now at least the ../ does link correctly now, when before it would assume the subdir path instead. Thanks for your help :-) Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/#findComment-1430603 Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 (edited) Well, requinix's solution should not work according that log (/var/www/html/dd/subdir), it should be work only if you moved the menu.php file outside of the project. In RedHat /CentOS /Fedora the web root directory is named html, so in that case "dd" is your project folder not a web root as you posted in your first post. Edited May 17, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/#findComment-1430630 Share on other sites More sharing options...
port80 Posted May 26, 2013 Author Share Posted May 26, 2013 Well, requinix's solution should not work according that log (/var/www/html/dd/subdir), it should be work only if you moved the menu.php file outside of the project. In RedHat /CentOS /Fedora the web root directory is named html, so in that case "dd" is your project folder not a web root as you posted in your first post. Thank you for the correction on the webroot. I can see the difference in the server root versus the directory root for a project, I'll keep that in mind for next time. I do have multiple project folders in the webroot of /var/www/html/ . So I understand you correctly, the $_SERVER["DOCUMENT_ROOT"] should not work as that refferences the /var/www/html/ and not /var/www/html/dd/ ? Is that right? So the fix should really be the absolute path issue as requinix suggested? Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/#findComment-1432412 Share on other sites More sharing options...
jazzman1 Posted May 26, 2013 Share Posted May 26, 2013 So I understand you correctly, the $_SERVER["DOCUMENT_ROOT"] should not work as that refferences the /var/www/html/ and not /var/www/html/dd/ ? Is that right? It depends how looks like the root directive in Apache conf, by default is: DocumentRoot "/var/www/html" When you create new projects on the same web root, you should avoid using absolute paths unless you really need them. Quote Link to comment https://forums.phpfreaks.com/topic/278020-php-include-not-working/#findComment-1432438 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.