Running php from an .htm page

Discussion in 'PHP' started by larryweiss, May 30, 2006.

  1. #1
    How do you call a php script from an .htm page, without renaming the page to .shtml.

    It can be done, as shown by some add network code working on one of my sites which does the job.

    The code is as follows
    This line was added to the htaccess file
    The usual coop files are of course included in the site.

    I do not know beans about php. Can some suggest a snippet, along with any htaccess code, that would call a php script from an thm page?

    Would the php file have to be same directory as the htm file, or is there some general path to the php file from anywhere?

    Thanks
     
    larryweiss, May 30, 2006 IP
  2. Shoemoney

    Shoemoney $

    Messages:
    4,474
    Likes Received:
    588
    Best Answers:
    0
    Trophy Points:
    295
    #2
    its possible you can not override the hosts addtype param.

    Do you host the site yourself (I am guessing if you did you would just use .php)
     
    Shoemoney, May 30, 2006 IP
  3. hextraordinary

    hextraordinary Well-Known Member

    Messages:
    2,171
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Redirect ".htm" to application/x-httpd-php.
     
    hextraordinary, May 30, 2006 IP
  4. larryweiss

    larryweiss Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #4
    I would like to have fresh content on my pages. My approach is to include changing, relevant text on almost pages of the site. I have a script that loads random strings, (The list of strings is costomizable ). The script works fine with <!--#include virtual="/directory/scriptname.php" --> as long as the page is renamed to .shtml

    The site is at or near number 1 for all of its keywords/phrases, so I do not want to rename anything. Thats why I do not want to rename the pages from .htm to .shtml

    The site is hosted in a reseller account which I own, but is hosted by a regular hosting company.

    I tried adding the line
    to the top of my htaccess file, but all I got is was an error message.
     
    larryweiss, May 30, 2006 IP
  5. myhart

    myhart Peon

    Messages:
    228
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try adding the following to your .htaccess file.

    RemoveHandler .html .htm
    AddType application/x-httpd-php .php .htm .html

    Above works for me! If that does not work try adding the following at the top of the file along with the above code.

    RewriteEngine On
     
    myhart, May 30, 2006 IP
  6. myhart

    myhart Peon

    Messages:
    228
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sorry I didn't have time to completely answer your question in the above post.

    No, you can access any file on your website by adding the following to your HTML page.

    <?php include("/home/username/public_html/yourpage.php"); ?>

    Just make sure you get the path correct!

    If you have any more questions I will try to help. However I still have a lot to learn about PHP!
     
    myhart, May 30, 2006 IP
  7. Mystique

    Mystique Well-Known Member

    Messages:
    2,579
    Likes Received:
    94
    Best Answers:
    2
    Trophy Points:
    195
    #7
    If you want to use .shtml extension you need to add this:
     
    Mystique, May 30, 2006 IP
  8. TrippAllen

    TrippAllen Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I had this problem when I was hosting a site off of a Mac OS9 Webstar server (which has no PHP capability). I wanted to add in some simple database and visitor tracking capability, but didn't want to bother with a bunch of CGI scripts.

    Then I thought about the iframe HTML tag.
    You can use an iframe tag to include the php page somewhere in the html page. The php pages I used were hosted on a different server and brought in through the iframe.

    For simple things like visitor tracking scripting, it's pretty handy because you can set the iframe dimensions to 1px by 1px and it won't alter the current layout much at all.

    For complex stuff, it might not be worth the effort. Kinda depends on what you're trying to do with it.
     
    TrippAllen, May 31, 2006 IP
  9. Veselin Stoilov

    Veselin Stoilov Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    this works for me too

    AddType application/x-httpd-php .php .htm .html

    but you better ask your host if you can overwrite their configuration using htaccess file
     
    Veselin Stoilov, Jun 6, 2006 IP