Lexicon Posted November 5, 2010 Share Posted November 5, 2010 my directory on my mamp server looks like this; root/website/index.php I also have some files in a folder like this root/website/pages/files.php My include code is this include("functions.php"); When I try to include a file from the 'website' folder from a page in the 'pages' folder. It gives me errors that look like this. Warning: include(functions.php) [function.include]: failed to open stream: No such file or directory in /website/pages/contact.php on line 2 Warning: include() [function.include]: Failed opening 'functions.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5.3/lib/php') in /Applications/MAMP/htdocs/website/pages/contact.php on line 2 That's what it looks like.. I can't get it working. Quote Link to comment https://forums.phpfreaks.com/topic/217892-problems-with-php-includes-from-diff-file-paths-need-help/ Share on other sites More sharing options...
trq Posted November 5, 2010 Share Posted November 5, 2010 Considering website is 1 directory back up the tree you would need to use.... include "../functions.php"; Quote Link to comment https://forums.phpfreaks.com/topic/217892-problems-with-php-includes-from-diff-file-paths-need-help/#findComment-1130876 Share on other sites More sharing options...
Lexicon Posted November 5, 2010 Author Share Posted November 5, 2010 that worked. but now when i click on the website logo that is supposed to bring me to root/website/index.php it brings me to root/website/pages/index.php instead... and gives me 404 invalid page or whatever the header code I have is just a link that brings me to /index.php Quote Link to comment https://forums.phpfreaks.com/topic/217892-problems-with-php-includes-from-diff-file-paths-need-help/#findComment-1130899 Share on other sites More sharing options...
Rifts Posted November 6, 2010 Share Posted November 6, 2010 add / before the link so a link on your /pages/ pages will be like <a href="/index.php"> Quote Link to comment https://forums.phpfreaks.com/topic/217892-problems-with-php-includes-from-diff-file-paths-need-help/#findComment-1130917 Share on other sites More sharing options...
Lexicon Posted November 6, 2010 Author Share Posted November 6, 2010 that doesn't help because when I then click on the banner, it then brings me to root/index.php instead of root/website/index.php It seems this is something I am having a lot of problems with Quote Link to comment https://forums.phpfreaks.com/topic/217892-problems-with-php-includes-from-diff-file-paths-need-help/#findComment-1130958 Share on other sites More sharing options...
trq Posted November 6, 2010 Share Posted November 6, 2010 Paths are a pretty simple concept that allot of people seem to chock on for some reason. Links have nothing to do with php, you might post your problematic code within the HTML help board. Quote Link to comment https://forums.phpfreaks.com/topic/217892-problems-with-php-includes-from-diff-file-paths-need-help/#findComment-1130963 Share on other sites More sharing options...
inversesoft123 Posted November 6, 2010 Share Posted November 6, 2010 The links can be controlled by PHP with the help of $_SERVER['DOCUMENT_ROOT']; including example is include($_SERVER['DOCUMENT_ROOT'].'/root/myprojects/blah.php'); //and linking as echo "<a href=\"" . $_SERVER['DOCUMENT_ROOT'] . "/root/myprojects/blah.php\">My Project List</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/217892-problems-with-php-includes-from-diff-file-paths-need-help/#findComment-1130965 Share on other sites More sharing options...
trq Posted November 6, 2010 Share Posted November 6, 2010 $_SERVER['DOCUMENT_ROOT'] returns the full file system path to the root of the current vhost. This path means nothing to a browser which is only interested in the path *after* the document root. The rest is unreachable from the web. Quote Link to comment https://forums.phpfreaks.com/topic/217892-problems-with-php-includes-from-diff-file-paths-need-help/#findComment-1130967 Share on other sites More sharing options...
Lexicon Posted November 6, 2010 Author Share Posted November 6, 2010 thank you problem solved. I had to test the root directory on each page till I got it right, but it's done. Thanks for all the advice and tips that lead me to solve this problem, much appreciated. Gnight Quote Link to comment https://forums.phpfreaks.com/topic/217892-problems-with-php-includes-from-diff-file-paths-need-help/#findComment-1130971 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.