SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Run php on html page?

    Hello,

    I am doing work for a client who's server is shared windows. The current pages are all html. I want to be able to run php on the pages, like to include a menu, so I dont have to update every page by hand. I do this myself on unix servers with a line in an htaccess file : "AddType application/x-httpd-php .html" But of course this does nto work on a windows server.

    Is it possible to do this on a windows server? I never needed to know. I hate to change all the pages to php if at all possible. I know I could use SSI, but I'd still have to rename the pages, I'd rather do php in that case.

    Any suggestions?
    Thank you.

    ronnie

  2. #2
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this an Apache server? If so, you can add this line in the httpd.conf file:

    AddType application/x-httpd-php .html

    Somewhere below the original PHP lines.
    So hold me when I'm here
    Right me when I'm wrong
    Hold me when I'm scared
    Love me when I'm gone.

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2001
    Location
    Tucson, Arizona
    Posts
    1,858
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ronnie
    But of course this does nto work on a windows server.
    It does if the Web server you're running is Apache.

  4. #4
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm... By Windows server I assume you are using IIS ? I would beg believe and in this event I would seriously recommend that you dump that server and upgrade to Apache

  5. #5
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Believe me, if it was up to me, I would have already done that, maybe I will soon. And yes I believe it is IIS.

    But still need this to work for now.

    ronnie

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm.... All pages are html ? My thoughts if you want server-side functionality without too much agro would be to use Javascript ?

    You'd only need to put one link in a page to serve PHP functionality though this in it's self might not be pratical since you'd still need PHP on a server somewhere.

    For more info on using PHP and Javascript look over the content feed article at www.devarticles.com which would get you started and give you a few ideas ?

    Apart from that I suppose you'd be better off to take the plunge and set up Apache and maybe begin using Templates ?

    Sorry I can't be more helpful though...

  7. #7
    SitePoint Guru wild boar's Avatar
    Join Date
    Aug 2003
    Location
    illinois
    Posts
    793
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know I could use SSI, but I'd still have to rename the pages

    You don't have to rename your files to .shtml to use ssi..

    All you have to do is edit your .htaccess file..

    It does make the server slower, but unnoticable.

  8. #8
    SitePoint Zealot OtherBaggs's Avatar
    Join Date
    Apr 2003
    Location
    Surrey, UK
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ronnie

    from Internet Information services (within control panel/ administrative tools) chose the properties of the website. From the home directory tab select configuration and Add

    The executable is the php4sapi.dll (in the PHP directory) and the extension is .html (or .htm)

  9. #9
    Thinking about Visual Thinking
    Join Date
    May 2003
    Location
    back in South Africa
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If, after all the advice you have received , you're still having the problem to solve, a possible workaround could be:

    Quote Originally Posted by Bringing static HTML to life with PHP
    Step 2. PHP Configuration

    Next is two, often overlooked, php.ini settings - auto_prepend_file and auto_append_file. What these do is "attach" a PHP script before (prepend) or after (append) the current script which is being executed by PHP. Think you can see where this is going now...

    Using a .htaccess file to set these, you might have;

    php_value auto_prepend_file /home/username/before.php
    php_value auto_append_file /home/username/after.php

    Note it's probably a good idea to switch off the short_open_tag setting as well, in case the pages contain anything like an XML processing instruction like .


    Step 3. Output Control

    Now you need to "catch" the HTML before is gets served to the browser for which PHP's output control functions are perfect.

    Here's what the files that are being prepended and appended might include;

    <?php
    // before.php

    // Start output buffering
    ob_start();
    ?>

    That gets executed before the orignal HTML page is "parsed" by PHP.

    <?php
    // after.php

    // Store the contents of the buffer in a variable
    $page = ob_get_contents();

    // End and clean the buffer
    ob_end_clean();

    /**
    * Manipulate the $page variable here
    */

    // Display the page
    echo $page;
    ?>

    The after.php "captures" the HTML as a string into the $page variable, allowing you to manipulate it in some manner, before it gets sent to the browser.

    And that's basically it. No HTML files are directly modified. All URL's remain the same.
    See the phpPatterns() Article for more information in depth.

    If .htaccess manipulation is not possible, than just combine befor.php and after.php in index.php and include the HTML file to capture the content for further manupulation.


Bookmarks

Posting Permissions

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