Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    6

    Unanswered: PHP script embedded in .html file: possible?

    I want to be able to embedd PHP scripts in .html files (I am using apache). Is this possible?

    I added this to httpd.conf:
    AddType application/x-httpd-php .html

    But when I try a simple script, it doesn't seem to work. For example:

    <html>
    <head>
    <title>**</title>
    </head>
    <body>
    <?php

    echo "hello";

    ?>
    </body>
    </html>

    I just get a blank page, like it is not recognizing the script, or ignoring it.
    Can somebody tell me if this is possible, and if so what else do I have to do to make the script embeddable in a .html file.

    <? T H A N K S ?>

  2. #2
    Join Date
    Jan 2004
    Posts
    545
    Provided Answers: 4
    You have to name the document <name>.php.
    Otherwise the server doesn't recognise it as containing php-code, and doesn't execute it.

    First of all, you have to install php on your server of course .
    I'm not crazy, I'm an aeroplane!

  3. #3
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    You can use an Iframe to include a php file. ie you have to make a php file and then include it through an iframe.

    Try this. There are lots more other methods.. Have to search for that
    This will serve you need for now

    Regards
    Rajesh

  4. #4
    Join Date
    Mar 2004
    Posts
    6
    Not sure about the iframe. I don't want to have to learn about another technology to include this (PHP) technology inside the older (HTML) technology. I think this must be a bug in either Apache or PHP.

    Well, I got it working on my outside webhost using .htaccess. But this then gave rise to another new and interesting problem: When I put the exact same .htaccess file on my laptop windows-based Apache server (and restart), when I browse to the same .html file (that worked on the unix-based Apache)
    a dialog window opens, FILE DOWNLOAD, ie the same as if I had clicked on some link that was linked to an application; it's asking if I would like to save it to my computer!

    Anybody know why the .htaccess would act so differently in those 2 situations?

    And, can anyone recommend a URL where I can check exactly which dll's etc need to be in which folders when installing PHP. I want to check my installation and the install.txt that comes with PHP is terrible, littered with spelling mistakes, cryptic-half sentences and the rest.

  5. #5
    Join Date
    Oct 2003
    Location
    Chicago, IL
    Posts
    34
    It is possible to do that. However, you will have to make a small modification to your web server. If you are using Apache server, you will have to go to the /conf/ directory of apache, and open httpd.conf file. Then, add ".html" and ".htm" to be passed through PHP engine, in addition to the ".php", ".php3" and ".phtml" that usually gets passed to the server.

    The good thing about it is that once you have this done, you can insert PHP code in any html file just like you would with JavaScript and it would get executed. The bad news however, is that it will slow down your server cosiderably, since every request to the web server would have to go through the PHP engine to be checked for embeded PHP code.

    Feel free to email me if you need more help on this topic.
    DigiOz Multimedia
    http://www.digioz.com

  6. #6
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    To use a iframe you just have to code the php in a .php file and include it as
    <iframe src="filename.php" width="" height="">
    This is what you have to do.. nothing more So simple. No server load tooo..
    Regards
    Rajesh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •