Jump to content

Recommended Posts

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???

Link to comment
https://forums.phpfreaks.com/topic/165559-php-include-not-working/
Share on other sites

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

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.

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! 

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.