getting a php include statement to work in an html document enabled for php

Posted on 2011-03-04
Last Modified: 2012-06-27

This page is a template for a site (eventually to be coded in css rather than what it is now).  We did not want to lose page rankings so it is set up to remain .html while including some php code:

The print statements work just fine, however there is an include statement that follows the "hello" and it doesn't work.  If I go straight to the file, it does as it should:

about Test.html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns=""><!-- InstanceBegin template="/Templates/expand_menu.dwt" codeOutsideHTMLIsLocked="false" -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>White Lotus</title>
<!-- InstanceEndEditable -->
<link href="css/global.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="js/swap.js"></script>
<script language="JavaScript" src="mm_menu.js"></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

<body onload="MM_preloadImages('images/registration2.gif','images/site_map2.gif')">
<table width="967" border="0" align="center" cellpadding="0" cellspacing="0">
    <td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <td align="center" valign="top"><img src="images/header1.gif" alt="Yoga Banner" width="322" height="105" /></td>
        <td align="center" valign="top"><img src="images/header2.gif" alt="Yoga Banner" width="323" height="105" /></td>
        <td align="center" valign="top"><img src="images/logo.gif" alt="Yoga Banner" width="322" height="105" border="0" usemap="#Map" /></td>
        <td align="center" valign="top"><img src="images/top_bar1.gif" alt="Yoga Banner" width="322" height="66" /></td>
        <td align="center" valign="top"><img src="images/top_bar2.gif" alt="Yoga Banner" width="323" height="66" /></td>
        <td align="center" valign="top"><img src="images/top_bar3.gif" alt="Yoga Banner" width="322" height="66" /></td>
    <td align="center" valign="top" background="images/background.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <td width="250" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr valign="top">
                    <td width="23" align="left" style="background: url(images/menu_L_bg.gif) right top repeat-y;"><img src="images/menu_L.gif" width="23" height="434" /></td>  <td align="left"><!-- InstanceBeginEditable name="menu" -->
					<?PHP print "hello"; include("/includes/test.php"); ?><!-- InstanceEndEditable --></td>
              <td align="left" valign="top" style="background:url(file:///C|/Documents%20and%20Settings/Em/My%20Documents/Websites/wlf/images/menu_B2.gif) right top no-repeat;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <td align="right" valign="top">&nbsp;</td>
                  <td align="left" valign="top"><img src="images/headings/newsletter.gif" width="116" height="20" style="margin-left:28px;" /></td>
                  <td align="right" valign="top"><table width="88%" border="0" cellspacing="0" cellpadding="0">
                      <td height="25" align="left" valign="top" class="bodytext">Receive our eNews<br />
                        and a complimentary<br />
                        <em>Principles of Yoga</em> article.
                      <td align="left" valign="top"><form method="post" action="epsmail.php" id=form1 name=form1>
 <input type="hidden" name="owner_id_enc" value="05948c-938328ac" />
<input type="hidden" name="function" value="Subscribe" />   

<input name="user_email" type="text" class="input" value="Enter Your Email Here" onfocus="javascript:if(this.value=='Enter Your Email Here'){this.value=''}" onBlur="if(this.value==''){this.value='Enter Your Email Here'}" style="height:20px; width:160px; margin:0;"/>
 <br />
 <input name="user_zip" type="text" class="input" value="Enter Your Zip Code Here" onfocus="javascript:if(this.value=='Enter Your Zip Code Here'){this.value=''}" onBlur="if(this.value==''){this.value='Enter Your Zip Code Here'}" style="height:20px; width:160px; margin:3px 0;"/> <input name="Submit2" type="submit" class="button" value="&raquo;" style="height:24px;" />
                      <td height="10" align="left" valign="top"></td>
                    <!--    <tr>
                <td align="left" valign="top" class="bodytext"><a href="" target="_blank"></a> &ndash; check for an API</td>
              </tr> -->
          <td align="left" valign="top"> 
            <!-- start indexing here -->
            <!-- InstanceBeginEditable name="master" -->Content will go here.<!-- InstanceEndEditable --> 
            <!-- stop indexing here -->
    <td align="center" valign="top"><img src="images/footer_T.gif" width="967" height="38" /></td>
    <td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <td width="250" align="left" valign="middle"><img src="images/footer_L.gif" width="250" height="36" /></td>
        <td align="left" valign="middle" background="images/footer.gif" class="footer">2500 San Marcos Pass &bull; Santa Barbara, CA 93105<br />
          Tel: 805-964-1944 &bull; Fax: 805-964-9617 &bull; eMail:
          <!-- This script can be used FREELY as long as this copyright message is intact: Mail Spam Blocker / Copyright (c) 2004 by Internet Marketing Solutions -->
          <a href="" style="color:#e6f1ad;">&#105;&#110;&#x66;&#x6f;&#x40;&#x77;&#x68;&#x69;&#x74;&#101;&#x6c;&#x6f;&#x74;&#x75;&#x73;&#x2e;&#x6f;rg</a></td>
        <td width="210" align="left" valign="middle" background="images/footer.gif" class="footer">&copy;
          <script language="JavaScript" type="text/javascript">
    today=new Date();
          White Lotus Foundation. <br />
          All Rights Reserved. </td>
        <td width="18" align="left" valign="middle"><img src="images/copyright.gif" width="18" height="36" /></td>
    <td align="center" valign="top"><img src="images/footer_B.gif" width="967" height="28" /></td>
    <td align="center" valign="top" class="footertext">White Lotus Foundation holds Yoga teacher training courses four times per year in Santa Barbara, CA at our beautiful retreat center in the mountains. Students attend from around the country to receive their yoga certification. For in-depth information on our <a href="teacher_training.html">Yoga Certification</a> Program, click Yoga Certification. Our courses are renowned around the world for their comprehensive content, individual attention to each student, and for the wonderful <br />
      transformational experience of studying with yoga pioneers and best selling authors, Ganga White and Tracey Rich. <br />
      White Lotus<sup class="tm">TM</sup> offered the first yoga teacher training and certification in America in 1968.<br />
      <p class="footertext" style="color:#000000; margin-top:8px;"><a href="" target="_blank">Web design &amp; development by NDIC</a>, designed in collaboration with Tracey Rich.</p></td>

<map name="Map" id="Map"><area shape="rect" coords="88,22,293,93" href="index.html" />
</map><script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "' type='text/javascript'%3E%3C/script%3E"));
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-5159729-6");
} catch(err) {}</script> 
<!-- InstanceEnd --></html>

Open in new window

Question by:emilysbca
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 83

Accepted Solution

Dave Baldwin earned 500 total points
ID: 35041319
Try removing the '/' before 'includes' and the '()'.
include "includes/test.php";

Open in new window


Expert Comment

ID: 35041586
Few ideas:

How about a meta refresh to a php page ?
would that work for the page ranking ?

Frame page ? (one frame being 100% by 100%, loading a php page)

create 1 gigantic div, and have javascript fill it with the html-output from a php page

What you also could do is instead of including a .js file
make it include to a .php:
<script type="text/JavaScript" src="js/variables.php"></script>

then ur php page, can do all the mojo u want, as long as you output variables via javascript again.
Example of the php file:


$bla = "w00t";

echo "var bla = '".$bla.';\n";

Header("content-type: application/x-javascript");


on the server, make edit the html MIME part to read PHP as well.

10yrs ago I managed to include html files in a html file, playing with templates top and bottom, but I forgot how, let alone if it wasn't a IE 5 and lower only thing ;P
LVL 17

Expert Comment

ID: 35043208
To include PHP code in a .html file you will need to override the default handling by editing the .htaccess file with something like:

RemoveHandler .html
AddType application/x-httpd-php .php .html

But, if you're going to be playing with .htaccess then you might as well just make it cleaner with a nice rewrite rule so the world sees .html, but you get to be .php on your side.  You can read more about that here:

On a side note, the php open tag should be <?php not <?PHP.

Author Closing Comment

ID: 35048343
Yes!!!!  Thank you!  I'm so glad it was that easy...
LVL 83

Expert Comment

by:Dave Baldwin
ID: 35048919
You're welcome and thanks for the points.

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question