4 replies
I have an html page and I want to include a PHP page within that html page. I've searched online for the solutions but they don't work.

Anyone have any other suggestions? I don't want the html page to be handled as a PHP in htaccess file. I've read something about a javascript code doing the job..?
#include #php
  • Profile picture of the author saschakimmel
    Sorry, you cannot include PHP on an HTML page without having the HTML page being parsed as a PHP page (.htaccess stuff).

    JavaScript can never do that because it is executed in the browser whereas PHP needs to be executed on the server.

    The only idea I have is using an IFrame in the HTML page which loads the PHP page, but this may not be what you're looking for.

    Maybe you could just rename the HTML page to .php and add the PHP code within that file?
    Signature

    ** Get my ViralListMachine software now for free and build your own list virally by giving away free stuff @ http://www.virallistmachinegiveaway.com **

    {{ DiscussionBoard.errors[1831249].message }}
    • Profile picture of the author wayfarer
      Originally Posted by Brightman View Post

      I've read something about a javascript code doing the job..?
      Originally Posted by saschakimmel View Post

      JavaScript can never do that because it is executed in the browser whereas PHP needs to be executed on the server.
      Technically, however, you could imitate a PHP include with JavaScript by loading snippets of HTML from an AJAX call during page load. This is probably what you were reading about. I wouldn't recommend you do this though, because it would cause accessibility problems, since it would cause problems for search engines reading the information and would not display to user agents which have JavaScript disabled.
      Signature
      I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
      {{ DiscussionBoard.errors[1833215].message }}
  • Profile picture of the author lisag
    Originally Posted by Brightman View Post

    I have an html page and I want to include a PHP page within that html page. I've searched online for the solutions but they don't work.

    Anyone have any other suggestions? I don't want the html page to be handled as a PHP in htaccess file. I've read something about a javascript code doing the job..?
    If you want to have .html treated as if it is php, as saschakimmel mentioned, make these changes to your .htaccess file.


    Code:
    AddHandler x-httpd-php .html .htm
    AddHandler php-script .php .html .htm
    AddHandler php5-script .php .html .htm
    AddType application/x-httpd-php .htm
    AddType application/x-httpd-php .html
    Signature

    -- Lisa G

    {{ DiscussionBoard.errors[1831991].message }}
  • Profile picture of the author SpamHat
    Originally Posted by Brightman View Post

    I have an html page and I want to include a PHP page within that html page. I've searched online for the solutions but they don't work.

    Anyone have any other suggestions? I don't want the html page to be handled as a PHP in htaccess file. I've read something about a javascript code doing the job..?

    If you don't need the output from the php file to *always* be fresh then you could cache the output as a html file and include this as the src of an iframe on your main page.

    Google will see this as a link to the iframed page and still index it, although it obviously won't pass any anchor reputation.
    {{ DiscussionBoard.errors[1843315].message }}

Trending Topics