1

I am including the footer content using this code

 <?php include 'footer.php'; ?>

It happens that I also have html files. How can I also include the footer in my html files?

user agent
  • 2,762
  • 6
  • 29
  • 74

2 Answers2

1

You can't, in order to include PHP files in your other files, all files need to be in the PHP extension.

In most cases, just renaming your HTML files to .php will do fine.

Lee
  • 3,854
  • 5
  • 19
  • 55
0

There is no native include in HTML. Do these other files need to be HTML? If not you could change them to PHP which still lets you use any HTML code plus the PHP include.

kalsowerus
  • 938
  • 8
  • 21
  • Unfortunately they have to be html. Is there a way around? – user agent Jul 26 '16 at 09:43
  • If you do not care about having the footer as a public file you could include it using JavaScript. See: [W3Schools - How To Include HTML](http://www.w3schools.com/howto/howto_html_include.asp) – kalsowerus Jul 26 '16 at 10:49
  • How would it work if I change the footer extension to htm (footer.htm)? – user agent Jul 26 '16 at 14:07
  • That should not make a difference. Have you tried W3Schools' HTML includes? In their TryIt-Editor I was able to successfully include a .asp file using their JavaScript code. I am sure it should work for any extension. – kalsowerus Jul 26 '16 at 14:16
  • @ kalsowerus.I am using this snippet from w3schools: http://www.w3schools.com/howto/tryit.asp?filename=tryhow_html_include_2 but for some reason it pulls the footer twice. Had a problem with the Internet but hopefully I don't have it again soon. – user agent Jul 27 '16 at 07:47
  • Remember that the TryIt-Editor does not save any of your changes, we only see the basic example behind that link. But using Google Chrome I checked the Requests generated by the script. It only pulled each of the includes once for me, just as intended. – kalsowerus Jul 27 '16 at 07:56
  • oh sorry I didn't think of that. Weird how funny this is behaving on my site. I actually thought I did something wrong so I added the same code on another page and again it pulled the footer twice. – user agent Jul 27 '16 at 07:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/118391/discussion-between-kalsowerus-and-wosley-alarico). – kalsowerus Jul 27 '16 at 08:00
  • All right..Sent you a message there – user agent Jul 27 '16 at 08:15