<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Denie&#039;s Tech Blog &#187; SSI</title>
	<atom:link href="http://blog.nataprawira.com/tech/category/ssi/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nataprawira.com/tech</link>
	<description>Information Technology for Life!</description>
	<lastBuildDate>Mon, 19 Jul 2010 09:20:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mixing PHP and SSI</title>
		<link>http://blog.nataprawira.com/tech/2009/03/24/mixing-php-and-ssi/</link>
		<comments>http://blog.nataprawira.com/tech/2009/03/24/mixing-php-and-ssi/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 03:54:53 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Mixing PHP and SSI]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=45</guid>
		<description><![CDATA[

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 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F24%2Fmixing-php-and-ssi%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F24%2Fmixing-php-and-ssi%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>This information is ONLY relevant to PHP4 and Apache 1.3</strong>. <em><strong>(BUT possible can be work also in PHP 5.x and Apache 2.x )</strong></em> We historically used PHP for all our web work. We have decided to migrate to <a href="http://www.zytrax.com/tech/lang/ruby/" target="_blank">ruby</a> for lots of reasons for all our new web development but we still have lots of PHP stuff hanging around.</p>
<h3>Background</h3>
<p>We regularly mix PHP and SSIs for the following reasons:</p>
<ul>
<li>Laziness &#8211; we have a lot of historic SSI stuff lying around and do not want to change it. We prefer evolution to revolution.</li>
<li>Appropriateness. Not all systems are good at everything. We find that conditionally selecting &#8216;lumps&#8217; of code to deliver browser specific pages (see <a href="http://www.zytrax.com/tech/web/browser_sniffing.html" target="_blank">server side browser sniffing</a>) is a lot cleaner and easier with SSI. That does not take away from either technology.</li>
</ul>
<h3>Nesting PHP and SSI</h3>
<p>The rules go like this (PHP4 and Apache 1.3 &#8211; we understand that Apache 2 is more flexible but have not yet made the transition):</p>
<ol>
<li>You can invoke SSI files from within PHP but must use the PHP <strong>virtual()</strong> function not <strong>include()</strong>. Variables set within PHP are NOT available to SSI so our favorite &#8216;wheeze&#8217; of supplying last modified dates to a standard footer do not work.</li>
<li>You can include SSI files using the <a href="http://www.zytrax.com/tech/web/ssi.htm#include" target="_blank">include virtual</a> SSI directive but the SSI filename must have a .shtml extension even if the XBitHack is being used.</li>
<li>You cannot include PHP files using the <a href="http://www.zytrax.com/tech/web/ssi.htm#include" target="_blank">include virtual</a> SSI directive.</li>
<li>Variables set within the General Apache section (we use this <a href="http://www.zytrax.com/tech/web/browser_sniffing.html" target="_blank">technique for server side bowser sniffing</a>) are available to both .php and .shtml files no matter how they are called.</li>
</ol>
<p><strong>Note:</strong> 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.</p>
<p><span id="more-45"></span></p>
<h2>Examples</h2>
<p>The following is our standard level 1 template implemented in SSI first and then PHP.</p>
<h3>SSI Version</h3>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Language" content="en-us"&gt;
&lt;meta http-equiv="Content-Type" content="text/html"&gt;
&lt;meta name="GENERATOR" content="company"&gt;
&lt;!--#include virtual="/templates/meta.html" --&gt;
&lt;title&gt;Level 1 template&lt;/title&gt;
&lt;!-- conditionally generated style sheet --&gt;
&lt;!--#include virtual="/templates/styles.shtml" --&gt;
&lt;!-- conditionally generated javascript code --&gt;
&lt;!--#include virtual="/scripts/javascript.shtml" --&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;!-- banner/page headings --&gt;
&lt;!--#include virtual="/templates/level_1.shtml" --&gt;
&lt;div class="page-content"&gt;

&lt;!-- unique page contents go here --&gt;

&lt;/div&gt;
&lt;!--#config timefmt="%B %d %Y" --&gt;
&lt;!--#set var="real_date" value="$LAST_MODIFIED" --&gt;
&lt;!--#include virtual="/templates/footer.shtml" --&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3>PHP Version</h3>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Language" content="en-us"&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=windows-1252"&gt;
&lt;meta name="GENERATOR" content="company"&gt;
&lt;meta name="keywords" content="blah, blah"&gt;
&lt;title&gt;Cool Tools&lt;/title&gt;
&lt;?php
&lt;!-- conditionally generated style sheet --&gt;
  virtual ("/templates/styles.shtml");
&lt;!-- conditionally generated javascript code --&gt;
  virtual ("/scripts/javascript.shtml");
?&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php
&lt;!-- banner/page headings --&gt;
  virtual ("/templates/level_1.shtml");
?&gt;
&lt;div class="page-content"&gt;

&lt;!-- unique page contents go here --&gt;

&lt;/div&gt;
&lt;?php
  $real_date = date("F d, Y.", getlastmod());
  include ("../templates/footer.php");
?&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>Notes:</strong></p>
<ol>
<li>You will notice that the styles, javascript and standard page navigation header use the PHP <strong>virtual()</strong> function because they contain SSI directives but the files are otherwise unchanged.</li>
<li>Our SSI &#8216;last modified&#8217; date &#8216;wheeze&#8217; 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 &#8220;footer.php&#8221; file and set the variable &#8216;real_date&#8217; using the PHP <strong>date()</strong> and  <strong>getlastmod()</strong> functions. This file is invoked with the <strong>include()</strong> function because it is a standard PHP file. In &#8216;footer.php&#8217; we just use &#8216;echo $real_date&#8217; 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.</li>
</ol>
<p><strong><a title="http://www.zytrax.com/tech/php/php_ssi.htm" href="http://www.zytrax.com/tech/php/php_ssi.htm" target="_blank">Original</a></strong></p>
<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/03/24/mixing-php-and-ssi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
