mail us  |  mail this page

products  |  company  |  support  |  downloads  |  isp services  |  contact us

Mixing PHP and SSI

This information is ONLY relevant to PHP4 and Apache 1.3. 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:

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.

Examples

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

SSI Version

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<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" -->
</head>
<body>
<!-- banner/page headings -->
<!--#include virtual="/templates/level_1.shtml" -->
<div class="page-content">
  
<!-- unique page contents go here -->

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

PHP Version

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<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>
<?php 
<!-- conditionally generated style sheet -->
  virtual ("/templates/styles.shtml");
<!-- conditionally generated javascript code -->
  virtual ("/scripts/javascript.shtml");
?>
</head>
<body>
<?php 
<!-- banner/page headings -->
  virtual ("/templates/level_1.shtml");
?>
<div class="page-content">
  
<!-- unique page contents go here -->

</div>
<?php
  $real_date = date("F d, Y.", getlastmod()); 
  include ("../templates/footer.php");
?>
</body>
</html>

Notes:

  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 its simpler in PHP but now we have to maintain two versions of our standard footer.



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.

Copyright © 1994 - 2008 ZyTrax, Inc.
All rights reserved. Legal and Privacy
site by zytrax
Hosted by super.net.sg
web-master at zytrax
Page modified: February 19 2008.

Tech

tech home
web stuff
dom stuff
css stuff
language stuff
regex stuff
rfc stuff
protocol stuff
cable stuff
lan wiring
rs232 wiring
howto stuff
survival stuff
wireless stuff
ascii codes
data rate stuff
telephony stuff
mechanical stuff
pc stuff
electronic stuff
tech links
open guides
RSS Feed Icon RSS Feed

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 Mozilla

web zytrax.com
add page to facebook add page to technorati.com add page to digg.com add page to del.icio.us add page to furl.net add page to stumbleupon add page to reddit.com mail this page feature print this page

HTML Stuff

W3C HTML 4.01
HTML5 (WHATWG)
W3C Page Validator
W3C DOCTYPE

XHTML Stuff

W3C XHTML Basic
W3C XHTML 1.1
W3C CSS1
W3C CSS2.1

DOM Stuff

W3C DOM
W3C DOM Events
Gecko DOM
MSIE DOM

Usability/Access

usability.gov
W3C -WAI
Web Style Guide
Michael L Bernard
WebAim.org

Jolly Useful

Peter-Paul Koch
A List Apart
Eric Meyer on CSS
glish.com
DOCTYPE definitions

Our Stuff

Our DOM Pages
DOM User Guide
DOM Explorer
DOM Navigation
CSS Techniques
CSS Short Cuts
CSS overview
Oh Really!

Javascript

ECMA-262

Pop-out Menus

webmasterbase.com
Brainjar Menubar
Our Lite JS Menus
Our CSS Menus
Tigra Menus

printer friendly

Print Page

SPF Record Conformant Domain Logo