Using php includes in .html files...possible?

Discussion in 'PHP' started by IanT, May 3, 2011.

  1. #1
    I am trying to update my main menu in each .html file, I thought it would be easier to use a php include and edit one mainMenu file, instead of hundreds of smaller files. Is it possible to use a php include in a .html file or does it NEED to be a .php file in order for the include to work?
     
    IanT, May 3, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    You need to be able to edit htaccess or your apache configuration.

    You would add this

    AddType application/x-httpd-php .php .htm .html

    Also, the AddType application/x-httpd-php is probably already in one of these files. If you have permission to edit it, just add the .html extension and restart apache.

    This will cause the server to parse all html files as php files. Make absolutely sure your html files do not have any unwanted php code in them, or it could be a security concern.
     
    jestep, May 3, 2011 IP
  3. IanT

    IanT Well-Known Member

    Messages:
    503
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #3
    thanks, okay now I tried this but now (in FF at least) it pops up with a window that says open file with..... and gives me a choice of programs from the list... did i do something wrong?
     
    IanT, May 3, 2011 IP
  4. ruvenf

    ruvenf Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    To run PHP on a html pages you can modify your .htaccess file
    add this on your .htaccess file (replace "yourhtmlpage.html" with your actual html file)
    <Files yourhtmlpage.html>
    AddType application/x-httpd-php .html
    </Files>
    This .htaccess code will make the PHP executable on your html file, and not on all of your html pages.
    now any thing in your html that starts with <? will run as php, to overcome it you need to echo it as a string.
     
    ruvenf, May 3, 2011 IP
  5. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    just run the php includes in a php file anything outside of the php tags or outputted in an echo statment will be outputted as basic html so you use you html in your php files
     
    srisen2, May 3, 2011 IP
  6. cute-sherry

    cute-sherry Peon

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Php is an open source you can use HTML file in PHP easily,php is a add type application if you can to add HTML just add .HTML extension and restart the Apache.etc........
     
    cute-sherry, May 4, 2011 IP
  7. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #7
    use mod rewrite name your file .php and then tell mod rewrite that .html is actually .php
     
    Bohra, May 4, 2011 IP
  8. clonepal

    clonepal Active Member

    Messages:
    128
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #8
    And here is a custom code that you can add to any file you want from your server. Let's say that you have a file named tutorials.html on your server, add this code to your .htaccess file:

    <Files tutorials.html>
    ForceType application/x-httpd-php
    </Files>

    This code will force your server to read the "tutorials.html" as a php file, hope that helps.

    -clonepal
     
    clonepal, May 5, 2011 IP