Running PHP inside a htm page

Discussion in 'PHP' started by dangoble, Feb 5, 2008.

  1. #1
    I run a IIS 6.0 Server 2003

    Test.php
    <?php
    // testing sessions
    // check to see if files are being created
    // in the session.save_path folder
    session_start();
    ?>
    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <p>
    The browser you're using is
    <?php echo $_SERVER['HTTP_USER_AGENT']; ?>
    </p>
    <p>
    <!-- test the browscap setup -->
    Your browser's capabilities are: <br/>
    <pre>
    <?php print_r(get_browser(null, true)); ?>
    </pre>
    </p>
    <?php phpinfo(); ?>
    </body>
    </html>

    This file runs fine from a browser as long as its named .php

    It will not run as an .htm file
    How do I set my server to make .htm run this script or if its not the server am I missing some sytax. I assume php can be run as htm.
    Fricking drivin me nuts for days
     
    dangoble, Feb 5, 2008 IP
  2. Possibility

    Possibility Peon

    Messages:
    350
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Traditionally, no. To run PHP you have to have your file named with .php. However, I believe there is some configuration for your server that will allow you to "embed" php into other pages - you would have to contact your host about this, and I doubt that they will change it. Why must your pages be .htm? If you needed to keep the .htm for linking/seo purposes, you could always use your .htaccess file to take the URL mysite.com/page.htm and actually call mysite.com/page.php
     
    Possibility, Feb 5, 2008 IP
  3. The Critic

    The Critic Peon

    Messages:
    392
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Put this in your .htaccess file
    
    AddHandler application/x-httpd-php .htm
    
    PHP:
     
    The Critic, Feb 5, 2008 IP
  4. ChaosFoo

    ChaosFoo Peon

    Messages:
    232
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ChaosFoo, Feb 5, 2008 IP
  5. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #5
    IIS is noob and costs money, uninstall it and install apache :)
     
    Kaizoku, Feb 5, 2008 IP
  6. The Critic

    The Critic Peon

    Messages:
    392
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Good point. I remember reading him say IIS but it must not have registered upstairs.

    Also a good point. :p
     
    The Critic, Feb 5, 2008 IP