ItsWesYo Posted March 22, 2009 Share Posted March 22, 2009 Need to Know: http://example.site.com/a/includes/header.php (Would contain the header) http://example.site.com/a/includes/footer.php (Would contain the footer) http://example.site.com/a/index.php (The index page of directory A) http://example.site.com/a/lettera/index.php (Another index of a higher directory) The Problem: Okay. It won't display my header and footer even though I correctly use the include function. I've tried everything, but just displays a white page with the text. Example: Let's say I make a page with a url of http://example.site.com/a/lettera/index.php. And I want to include http://example.site.com/a/includes/header.php and http://example.site.com/a/includes/footer.php So, I would use the PHP include function and use those. The problem is, the includes won't show up, just the page of /a/lettera/index.php. Help? Link to comment https://forums.phpfreaks.com/topic/150526-solved-no-include/ Share on other sites More sharing options...
Floydian Posted March 22, 2009 Share Posted March 22, 2009 Impossible to diagnose without some code... Link to comment https://forums.phpfreaks.com/topic/150526-solved-no-include/#findComment-790637 Share on other sites More sharing options...
ItsWesYo Posted March 22, 2009 Author Share Posted March 22, 2009 Okay, sorry about that..I'll post a quick example... http://example.site.com/a/includes/header.php <b>This is my header text example</b> http://example.site.com/a/includes/footer.php <b>This is my footer text example</b> http://example.site.com/a/index.php <?php include 'http://example.site.com/a/includes/header.php'; ?> text would go here <?php include 'http://example.site.com/a/includes/footer.php'; ?> http://example.site.com/a/lettera/index.php <?php include 'http://example.site.com/a/includes/header.php'; ?> text would go here <?php include 'http://example.site.com/a/includes/footer.php'; ?> Now of course, if you were to display the /a/letter/index.php page, it would show: This is my header text example text would go here This is my footer text example But it only shows 'text would go here' Link to comment https://forums.phpfreaks.com/topic/150526-solved-no-include/#findComment-790640 Share on other sites More sharing options...
Floydian Posted March 22, 2009 Share Posted March 22, 2009 The cause may be because you're attempting to include the file using a url. Is the file not on your server? If it is, use a regular file link, like: include './a/includes/header.php'; Hope that helps... Link to comment https://forums.phpfreaks.com/topic/150526-solved-no-include/#findComment-790641 Share on other sites More sharing options...
ItsWesYo Posted March 22, 2009 Author Share Posted March 22, 2009 It's still not working.. :/ Link to comment https://forums.phpfreaks.com/topic/150526-solved-no-include/#findComment-790647 Share on other sites More sharing options...
Floydian Posted March 22, 2009 Share Posted March 22, 2009 include './includes/header.php'; Try that. Note that I tooke the /a out of the path. Also, try using require(); instead of include so you can get an error message to pop up telling you why the file couldn't be included, if it can't be. When you get it working, you can change it back to include. Hope that helps... Link to comment https://forums.phpfreaks.com/topic/150526-solved-no-include/#findComment-790651 Share on other sites More sharing options...
Philip Posted March 22, 2009 Share Posted March 22, 2009 Personally I almost always use absolute paths. Typically it will be something like: /home/username/www/blah/file.php If you're going to use it one level up, here's what I would do: define('PATH', str_replace('lettera','',dirname(__FILE__)).'includes/'); include PATH.'header.php'; Same thing as above, just broken down into manageable chunks: <?php // Get the current path $currentPath = dirname(__FILE__); // Strip out the top folder (if it exists) $strippedPath = str_replace('/lettera','',$currentPath); // And instead, add in the includes $includePath = $strippedPath.'/includes/'; // Now use the variable in your include include $includePath.'header.php'; ?> Link to comment https://forums.phpfreaks.com/topic/150526-solved-no-include/#findComment-790660 Share on other sites More sharing options...
ItsWesYo Posted March 22, 2009 Author Share Posted March 22, 2009 You sir just helped me out, haha. Thank you! Link to comment https://forums.phpfreaks.com/topic/150526-solved-no-include/#findComment-790664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.