Mar 24 2009

Mixing PHP and SSI

This information is ONLY relevant to PHP4 and Apache 1.3. (BUT possible can be work also in PHP 5.x and Apache 2.x ) We historically used PHP for all our web work. We have decided to migrate to ruby for lots of reasons for all our new web development but we still have lots of PHP stuff hanging around.

Background

We regularly mix PHP and SSIs for the following reasons:

  • Laziness – we have a lot of historic SSI stuff lying around and do not want to change it. We prefer evolution to revolution.
  • Appropriateness. Not all systems are good at everything. We find that conditionally selecting ‘lumps’ of code to deliver browser specific pages (see server side browser sniffing) is a lot cleaner and easier with SSI. That does not take away from either technology.

Nesting PHP and SSI

The rules go like this (PHP4 and Apache 1.3 – we understand that Apache 2 is more flexible but have not yet made the transition):

  1. You can invoke SSI files from within PHP but must use the PHP virtual() function not include(). Variables set within PHP are NOT available to SSI so our favorite ‘wheeze’ of supplying last modified dates to a standard footer do not work.
  2. You can include SSI files using the include virtual SSI directive but the SSI filename must have a .shtml extension even if the XBitHack is being used.
  3. You cannot include PHP files using the include virtual SSI directive.
  4. Variables set within the General Apache section (we use this technique for server side bowser sniffing) are available to both .php and .shtml files no matter how they are called.

Note: We would guess that the Apache environment for each type of file (.php and .shtml) is initialised to the same state as when the page is first called, whereas a nested .php files uses the same php environment and therefore reflects any dynamic changes.

Read more …