Solved

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

Posted on 2011-03-04
5
383 Views
Last Modified: 2012-06-27
Hi,

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:

http://www.whitelotus.org/aboutTest.html

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:  http://www.whitelotus.org/includes/test.php

about Test.html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/expand_menu.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<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 -->
</head>

<body onload="MM_preloadImages('images/registration2.gif','images/site_map2.gif')">
<table width="967" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <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>
      </tr>
      <tr>
        <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>
      </tr>
      
    </table></td>
  </tr>
  <tr>
    <td align="center" valign="top" background="images/background.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="250" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <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>
                  </tr>
              </table></td>
            </tr>
            <tr>
              <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">
                <tr>
                  <td align="right" valign="top">&nbsp;</td>
                </tr>
                <tr>
                  <td align="left" valign="top"><img src="images/headings/newsletter.gif" width="116" height="20" style="margin-left:28px;" /></td>
                </tr>
                <tr>
                  <td align="right" valign="top"><table width="88%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="25" align="left" valign="top" class="bodytext">Receive our eNews<br />
                        and a complimentary<br />
                        <em>Principles of Yoga</em> article.
 </td>
                    </tr>
                    <tr>
                      <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;" />
                        </form></td>
                    </tr>
                    <tr>
                      <td height="10" align="left" valign="top"></td>
                    </tr>
                    <!--    <tr>
                <td align="left" valign="top" class="bodytext"><a href="http://www.mailermailer.com/" target="_blank">MailerMailer.com</a> &ndash; check for an API</td>
              </tr> -->
                  </table></td>
                </tr>
                
              </table></td>
            </tr>
        </table></td>
          <td align="left" valign="top"> 
            <!-- start indexing here -->
            <!-- InstanceBeginEditable name="master" -->Content will go here.<!-- InstanceEndEditable --> 
            <!-- stop indexing here -->
          </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center" valign="top"><img src="images/footer_T.gif" width="967" height="38" /></td>
  </tr>
  <tr>
    <td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <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 www.myvasco.com Internet Marketing Solutions -->
          <a href="mailto:info@whitelotus.org" 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();
    year0=today.getFullYear();
    document.write(year0);
//-->
          </script>
          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>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td align="center" valign="top"><img src="images/footer_B.gif" width="967" height="28" /></td>
  </tr>
  <tr>
    <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="http://www.ndic.com" target="_blank">Web design &amp; development by NDIC</a>, designed in collaboration with Tracey Rich.</p></td>
  </tr>
</table>


<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 + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-5159729-6");
pageTracker._trackPageview();
} catch(err) {}</script> 
</body>
<!-- InstanceEnd --></html>

Open in new window

0
Comment
Question by:emilysbca
5 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 35041319
Try removing the '/' before 'includes' and the '()'.  http://us3.php.net/manual/en/function.include.php
include "includes/test.php";

Open in new window

0
 
LVL 3

Expert Comment

by:Duboux
ID: 35041586
Few ideas:

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



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



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



4)
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:

<?php

$bla = "w00t";

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

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

?>


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



6)
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
0
 
LVL 17

Expert Comment

by:GreatGerm
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: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

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

Author Closing Comment

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

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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