cozbaldwin Posted July 10, 2009 Share Posted July 10, 2009 I never thought it was this simple. But a friend recently told me it was, in fact, this simple. (Turns out... it's not that simple. For me. Today, anyway.) I just want a way to call my header and footer from within my .php page. Ideally, I'd like my header and footer to be a .php file too, but the research I've done so far seems to suggest it has to be .html or .shtml. Is this true? So - on my index.php page, I put the following lines: <?php session_start(); include("http://www.mysite.com/header.html"); ?> i've tried "include" and I've tried "require_once" which I learned by searching these forums. I've tried with and without the session start. I've also tried writing it like this: <?php session_start();include 'http://www.mysite.com/header.html'; ?> I can't get the darned thing to show up! The div I've placed this function in remains empty - the rest of the page loads fine. I've left off the head and various meta data from the .html I'm calling -- and even when trying to include a .php file I've tried with and without the meta data & head. So what else should I be looking for??? Quote Link to comment https://forums.phpfreaks.com/topic/165559-php-include-not-working/ Share on other sites More sharing options...
sKunKbad Posted July 11, 2009 Share Posted July 11, 2009 URL include is probably turned off, as it should be, in your php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/165559-php-include-not-working/#findComment-873288 Share on other sites More sharing options...
cozbaldwin Posted July 11, 2009 Author Share Posted July 11, 2009 URL include is probably turned off, as it should be, in your php.ini file. I'm guessing you say that because of safety issues? Is there a different method that's safe and widely recommended for doing what I'm looking to do? Quote Link to comment https://forums.phpfreaks.com/topic/165559-php-include-not-working/#findComment-873301 Share on other sites More sharing options...
xtopolis Posted July 11, 2009 Share Posted July 11, 2009 Where is the header/footer located? Is it on the same webserver, and in the same folder as index.php? Or is it on another website? You can read here about the limitations and warnings for include: http://us3.php.net/manual/en/function.include.php To directly answer your question, it is not limited to .html/shtml in the least. The likely issue is either a) you are trying to remotely include [like skunk suggested] or b) have the wrong reference to location Quote Link to comment https://forums.phpfreaks.com/topic/165559-php-include-not-working/#findComment-873312 Share on other sites More sharing options...
PFMaBiSmAd Posted July 11, 2009 Share Posted July 11, 2009 You should be including files using a local file path, not a URL. When you use a URL to include a file, it generates a http request back to your web server to get that file, the same as if you browsed to the file being included. This takes about 100 times longer to do for each included file than if the file is read through the file system and just slows down the generation of every page that does it. Quote Link to comment https://forums.phpfreaks.com/topic/165559-php-include-not-working/#findComment-873313 Share on other sites More sharing options...
cozbaldwin Posted July 11, 2009 Author Share Posted July 11, 2009 Where is the header/footer located? Is it on the same webserver, and in the same folder as index.php? Or is it on another website? You can read here about the limitations and warnings for include: http://us3.php.net/manual/en/function.include.php To directly answer your question, it is not limited to .html/shtml in the least. The likely issue is either a) you are trying to remotely include [like skunk suggested] or b) have the wrong reference to location The header and footer are both in the same root directory as the index.php. And -- AH HAH! I thought the direct URL would ensure the path wouldn't get messed up if this function gets called from different directories. So I just now switched to calling "header.html" and it works! But... calling "header.php" does NOT work. In fact, the page begins to load but stops dead in its tracks as soon as it hits this piece of code. Now what? p.s. - I didn't even realize Skunk was insinuating I was trying to illegally include someone else's content. I resent that! Quote Link to comment https://forums.phpfreaks.com/topic/165559-php-include-not-working/#findComment-873329 Share on other sites More sharing options...
xtopolis Posted July 11, 2009 Share Posted July 11, 2009 Well, is there a file called header.php? I am not 100% on this, but does that file also have the appropriate <?php ?> tags in it? Any errors from your tests rather than "it doesn't work" ? And skunk wasn't insinuating that that I know. It is for your own safety. Remotely accessing content you have no control over is a bad idea. What if it changes without your knowledge? Quote Link to comment https://forums.phpfreaks.com/topic/165559-php-include-not-working/#findComment-873332 Share on other sites More sharing options...
cozbaldwin Posted July 11, 2009 Author Share Posted July 11, 2009 Well, is there a file called header.php? I am not 100% on this, but does that file also have the appropriate <?php ?> tags in it? Any errors from your tests rather than "it doesn't work" ? And skunk wasn't insinuating that that I know. It is for your own safety. Remotely accessing content you have no control over is a bad idea. What if it changes without your knowledge? Damn. There was some issue with the php version of the header. Extra code. I fixed it. Everything looks great now. IT was really that relative URL thing that I was totally screwed up on. Thanks for the assistance! And for the record, I'm not really offended by any insinuation or lack thereof. I totally understand. And I'm totally using this as it was intended to be used, for my one site and linking only to within my site. Quote Link to comment https://forums.phpfreaks.com/topic/165559-php-include-not-working/#findComment-873353 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.