mail us  |  mail this page

contact us
training  | 
tech stuff  | 

Tech stuff - Mixing PHP and SSI

We urrently use this technique with PHP5 and Apache 2.x (2.4 currently). We historically used PHP for all our web work. We have decided to migrate to ruby for all our new web development but we still have lots of PHP stuff hanging around that we upgrade and modify as necessary.


We regularly mix PHP and SSIs for the following reasons:

Nesting PHP and SSI

The rules go like this:

  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 browser 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.


The following is our standard level 1 template implemented in SSI first and then PHP.

SSI Version

<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html">
<meta name="GENERATOR" content="company">
<!--#include virtual="/templates/meta.html" -->
<title>Level 1 template</title>
<!-- conditionally generated style sheet -->
<!--#include virtual="/templates/styles.shtml" -->
<!-- conditionally generated javascript code -->
<!--#include virtual="/scripts/javascript.shtml" -->
<!-- banner/page headings -->
<!--#include virtual="/templates/level_1.shtml" -->
<div class="page-content">
<!-- unique page contents go here -->

<!--#config timefmt="%B %d %Y" -->
<!--#set var="real_date" value="$LAST_MODIFIED" -->
<!--#include virtual="/templates/footer.shtml" -->

PHP Version

<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="company">
<meta name="keywords" content="blah, blah">
<title>Cool Tools</title>
<!-- conditionally generated style sheet -->
  virtual ("/templates/styles.shtml");
<!-- conditionally generated javascript code -->
  virtual ("/scripts/javascript.shtml");
<!-- banner/page headings -->
  virtual ("/templates/level_1.shtml");
<div class="page-content">
<!-- unique page contents go here -->

  $real_date = date("F d, Y.", getlastmod()); 
  include ("../templates/footer.php");


  1. You will notice that the styles, javascript and standard page navigation header use the PHP virtual() function because they contain SSI directives but the files are otherwise unchanged.
  2. Our SSI 'last modified' date 'wheeze' for the footer does not work in a mixed PHP/SSI environment (because you cannot pass variables between PHP and SSI). Instead we have to create a "footer.php" file and set the variable 'real_date' using the PHP date() and getlastmod() functions. This file is invoked with the include() function because it is a standard PHP file. In 'footer.php' we just use 'echo $real_date' to place our last modified date in the output stream. Yes, it's simpler in PHP but we have to maintain two versions of our standard footer. Sigh.

Problems, comments, suggestions, corrections (including broken links) or something to add? Please take the time from a busy life to 'mail us' (at top of screen), the webmaster (below) or info-support at zytrax. You will have a warm inner glow for the rest of the day.

Tech Stuff

RSS Feed Icon

If you are happy it's OK - but your browser is giving a less than optimal experience on our site. You could, at no charge, upgrade to a W3C standards compliant browser such as Firefox




Icons made by Icomoon from is licensed by CC 3.0 BY
share page via facebook tweet this page


email us Send to a friend feature print this page Display full width page Decrease font size Increase font size


HTML Stuff

W3C HTML 4.01
HTML5 Reference
W3C Page Validator

CSS Stuff

W3C CSS2.1
W3C CSS2.2
Default Styles
CSS3 Selectors
CSS 3 Media Queries
CSS 3 Colors

DOM Stuff

W3C DOM 3 Core
W3C 3 Events

Web Style Guide

Useful Stuff

Peter-Paul Koch
A List Apart
Eric Meyer on CSS

Our Stuff

Our DOM Pages
DOM Navigation
Liquid Layout
CSS Short Cuts
CSS overview
CSS One Page

Javascript Stuff



CSS Technology SPF Record Conformant Domain
Copyright © 1994 - 2024 ZyTrax, Inc.
All rights reserved. Legal and Privacy
site by zytrax
hosted by
web-master at zytrax
Page modified: January 20 2022.