How to insert .php file into .htm file

Discussion in 'HTML & Website Design' started by globalcashsite, Feb 12, 2010.

  1. #1
    globalcashsite, Feb 12, 2010 IP
  2. nadiralishah_webexpert

    nadiralishah_webexpert Guest

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can add .htm into .php like this, but you cannot add a .php file into .htm
     
    nadiralishah_webexpert, Feb 12, 2010 IP
  3. globalcashsite

    globalcashsite Peon

    Messages:
    806
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Very strange if we can add php code into html document then why we can't add php file into it?

    GCS
     
    globalcashsite, Feb 12, 2010 IP
  4. fierceservers

    fierceservers Peon

    Messages:
    338
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can add PHP to an html file! Just use the include command like above, but you also need to place something in the .htaccess file of that directory:
     
    fierceservers, Feb 13, 2010 IP
  5. nadiralishah_webexpert

    nadiralishah_webexpert Guest

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no my friend.. for seo purposes, people like to set php files work as .html.. i mean actually they are php files but will open on the browser if we set .htacess settings to treat .php files as .html.. because then search engines will take it as static page and static pages are always good for good search engine rankings.. you cannot include a php file into .htm file.. Infact, the tags he is trying to use to include are php tags, that not works in html.. he is using <? ?> to include.. these tags are for .php files..
     
    nadiralishah_webexpert, Feb 13, 2010 IP
  6. danniel

    danniel Banned

    Messages:
    298
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    To insert a php file into a html file you can use iframe.
     
    danniel, Feb 13, 2010 IP
  7. nadiralishah_webexpert

    nadiralishah_webexpert Guest

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    no, this is not strange.. actually, php is dynamic server side programming language.. and HTML is static client side code.. server not understand .html, it just throws .html code to the browser.. and server understands server side scripting php and convert or compile or interpret it into some other code that browser can understand, that code can be html, sometimes xml, depends what php programming want to display or writing to browser..

    html file exists on browser, and php resides on server, html cannot include php.. but php can include html on server side and then at once can through the final result to browser that browser can understand..

    but there is one way if you want to include something in html from php file, then my expert advice to you is to use AJAX (asynchronous javascript and xml).. code an smart javascript in your html file, that javascript will call php file without let the browser refresh, and php file will get executed on server side and will through the output of php file into the browser, then without the page refresh, javascript will get response from the php file output that you can use or include in your html file using javascript..
     
    nadiralishah_webexpert, Feb 13, 2010 IP
  8. nadiralishah_webexpert

    nadiralishah_webexpert Guest

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    yes iframe is an option only if he just need to display something from php file into .html.
     
    nadiralishah_webexpert, Feb 13, 2010 IP
  9. Sapphiro

    Sapphiro Well-Known Member

    Messages:
    1,242
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    175
    #9
    hmmm but iframe doesnt look very professional though...
     
    Sapphiro, Feb 13, 2010 IP
  10. nadiralishah_webexpert

    nadiralishah_webexpert Guest

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    u can give it a professional look by not displaying the iframe borders and take care of the height and width.
     
    nadiralishah_webexpert, Feb 13, 2010 IP
  11. fierceservers

    fierceservers Peon

    Messages:
    338
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #11
    You're giving a bunch of false information. You CAN include a PHP file into an HTML file, I've done it many times and for several of my clients. Doing what I stated above alone will allow you to include PHP commands in an HTML document.

    If you didn't notice the ".php" section in the .htaccess line:
    And as for SEO, I really have a hard time assuming that search engines give preference to HTML-only websites, and in either event, the browser or search engine crawler doesn't even see that it's PHP code because the server parses it and spits out HTML for the browser to understand and layout. The iframe is most likely what will cause SEO problems, not PHP.
     
    Last edited: Feb 13, 2010
    fierceservers, Feb 13, 2010 IP
  12. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #12
    You type this into your .htm file.

    <?PHP
    include_once("example.php");
    ?>

    Make sure your files are in the correct place (same directory) though or you get an error and make sure in your PHP file you have open and closing php tags.
     
    Imozeb, Feb 13, 2010 IP
  13. superstan

    superstan Peon

    Messages:
    244
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    use a javascript to call the php page in html
    thats the best way
     
    superstan, Feb 13, 2010 IP
  14. nadiralishah_webexpert

    nadiralishah_webexpert Guest

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    using your suggested way, you can only execute a php file from html, but you cannot include.. there is a difference between execute and include concept..
     
    nadiralishah_webexpert, Feb 14, 2010 IP
  15. nadiralishah_webexpert

    nadiralishah_webexpert Guest

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Yes mate, you are right.. here is the detailed tutorial about this;

    http://php.about.com/od/advancedphp/p/html_php.htm
     
    nadiralishah_webexpert, Feb 14, 2010 IP
  16. globalcashsite

    globalcashsite Peon

    Messages:
    806
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Hi buddy

    I added this into .ht file but when I opened my .htm page browser don't display page instead a page save window open to save this page.

    What is problem here? And I am getting this error where I included php file

    [an error occurred while processing this directive]

    GCS
     
    globalcashsite, Feb 14, 2010 IP