Embedded PHP code not executed in HTML page

Discussion in 'Apache' started by MrUmunhum, May 24, 2010.

  1. #1
    Hi group,

    I have an HTML page that I want to run some PHP code. I found several "How tos" about this but I can't get it to work. The code is very simple:
    Code:
    
    cat  test.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
      <meta content="text/html; charset=ISO-8859-1"
     http-equiv="content-type">
      <title>Test</title>
      <meta content="william estrada" name="author">
    </head>
    <body style="background-color: rgb(204, 204, 204); color: windowtext;"
     link="#0000ee" vlink="#551a8b" alink="#ee0000">
    <center>
    <?php
    echo "Last modified: " . date ("F d Y", getlastmod());
    ?>
    </body>
    </html>
    Code (markup):
    My php.conf look like this:
    cat /etc/httpd/conf.d/php.conf
    #
    # PHP is an HTML-embedded scripting language which attempts to make it
    # easy for developers to write dynamically generated webpages.
    #
    <IfModule prefork.c>
      LoadModule php5_module modules/libphp5.so
    </IfModule>
    <IfModule worker.c>
      LoadModule php5_module modules/libphp5-zts.so
    </IfModule>
    
    #
    # Cause the PHP interpreter to handle files with a .php extension.
    #
    AddHandler php5-script .php
    AddType text/html .php
    
    #
    # Add index.php to the list of files that will be served as directory
    # indexes.
    #
    DirectoryIndex index.php
    
    #
    # Uncomment the following line to allow PHP to pretty-print .phps
    # files as PHP source code:
    #
    AddType application/x-httpd-php-source .phps
    Code (markup):
    Any .php file works OK but not any embedded php code.

    What am I missing??

    Thanks for your time.
    __________________
    William Estrada
    MrUmunhum@popdial.com
    Mt-Umunhum-Wireless.net ( http://64.124.13.3 )
     
    MrUmunhum, May 24, 2010 IP
  2. JonTJ

    JonTJ Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you need to save your test.html file as test.php for the embedded php scripts to work
     
    JonTJ, May 27, 2010 IP
  3. MrUmunhum

    MrUmunhum Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Not true. I fixed it by changing my conf file:
    This
    AddType application/x-httpd-php .php
    to
    AddType application/x-httpd-php .php .html
    Code (markup):
    This should be a default??
     
    MrUmunhum, May 27, 2010 IP
  4. trevHCS

    trevHCS Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Wouldn't recommend doing it in the main config file as that'll mean it'll run all .html pages through PHP which won't add a lot of load to the server, but will add load that you probably don't need to. Maybe the better idea would be to add a line to .htaccess

    AddType application/x-httpd-php .html

    ...so it'll only apply to the .html files in the web site in question.

    Trev
     
    trevHCS, May 28, 2010 IP