PHP include - Something Like this for HTML

Discussion in 'PHP' started by BlogSalesman, Oct 25, 2007.

  1. #1
    I really like how in PHP you can include another file, and it drops that code into the webpage. Like when you have a menu, you just add the menu code to menu.php and include that file in the proper place in all your webpages.

    I have an HTML file, and I was wondering if I could do the same thing. Say I have a header and menu, and I want to drop that on each HTML page, but I don't want to add the code to each page. I want the code in one place, and then when I need to make changes, I just change the one file.

    It is probably something that can't be done, or probably something very simple that I am overlooking.
     
    BlogSalesman, Oct 25, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    This doesn't work by default, BUT there are a few workarounds.

    Create an .htaccess file and place this inside:
    
    AddType application/x-httpd-php .html .htm .php
    
    Code (markup):
    Now PHP will parse all HTML files too (which makes it a bit slower), but you can use your regular include() in HTML files.


    And another method is using SSI. But you have to change your HTML extensions to .shtml
    
    <!--#include file="file.html" -->
    
    Code (markup):
     
    nico_swd, Oct 25, 2007 IP
  3. deadlyp99

    deadlyp99 Member

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    You could also use frames. Just google around for those. They are easy but pretty much suck.
     
    deadlyp99, Oct 25, 2007 IP
  4. BlogSalesman

    BlogSalesman Well-Known Member

    Messages:
    1,687
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #4
    I guess you can:

    
    <!--#include virtual="includes/tab_nav.inc"-->
    
    Code (markup):
    Just read nico's comment. The example I see of this is ASP.NET, so .aspx page. I will have to try it in HTML.
     
    BlogSalesman, Nov 9, 2007 IP
  5. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #5
    i think the easiest approach is just to rename his .html files to .php instead
     
    serialCoder, Nov 9, 2007 IP
  6. armatik

    armatik Peon

    Messages:
    27
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I think it'd be better if you just renamed your .html file to .php, since that seems a bit complicated, and impractical since parsing all HTML files is.. well, impractical. :cool:
     
    armatik, Nov 9, 2007 IP
  7. rahmat

    rahmat Active Member

    Messages:
    270
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #7
    It is good for SEO.
     
    rahmat, Nov 9, 2007 IP
  8. armatik

    armatik Peon

    Messages:
    27
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    How can it be that parsing files that don't even have any code, except for a few, be of any help to SEO? Unless you mean .html over .php, in that case, I've never heard of that, but it doesn't seem practical to try and keep your website's speed as fast as you can.
     
    armatik, Nov 9, 2007 IP
  9. rahmat

    rahmat Active Member

    Messages:
    270
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #9
    I mean .html over .php
     
    rahmat, Nov 9, 2007 IP