[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 668
  • Last Modified:

php and ssi

Hi i'm trying to combine a php file with an htm file which contains server side includes.  

html:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

<html>

<head>

<title></title>

<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen"/>

<!--#set var="titleimage" value="/images/titles/heed.gif" -->

<!--#include virtual="/ssi/header-with-search.htm"-->

<!--#include virtual="ssi/leftnav.htm"-->

blah

<!--#include virtual="ssi/footer.htm"-->

</body>

</html>

php:

<?php
include("facedusoc//include//functions.php");
?>

<html>

<head>

<title></title>

<link rel="stylesheet" href="http://www.dundee.ac.uk/facedusoc/css/style.css" type="text/css" media="screen"/>

<?php
      $dir = opendir('.');
      while (($file = readdir($dir)) !== false)
      {
            if ($file != "." && $file != "..")
            {
                  if (!strpos($file, '.'))
                  {
                        $ext  [] = '';
                        $fname[] = $file;
                  }
                  else
                  {
                      $ext  [] = substr(strrchr($file, '.'), 1);
                      $fname[] = substr($file, 0, strrpos($file, '.'));
                    }
              # some additional information about files, if needed
 
                    $size[] = filesize($file);
                  $the_array[] = $file;
            }
      }
      closedir($dir);
?>

</head>

<body>

<h1><?php  print str_replace("_","/",basename(dirname($_SERVER['PHP_SELF']))); ?></h1>

<br>

<table border="0" cellpadding="2" cellspacing="0" id="content">

<?php
      # to sort arrays, use array_multisort() function.
      # write all arrays as parameters. you should notice the order of arrays.
      # to sort by extension, then by filename, then by file size:
      array_multisort($ext, $fname, $size);
      for ($n = 0; isset($fname[$n]); $n++ )
      {
            $file = $fname[$n].($ext[$n]?'.'.$ext[$n]:'');
             
            if ($file != "index.php" && $file != "dir.txt" && $file != ".htaccess" && $file != "facedusoc.txt")
            {
                  $filesize = filesize ($file);
                  $filesizekb = round($filesize / 1000);
                  if ($filesizekb < "1000") {
                  $filesizet = $filesizekb;
                  $filesizet .= " KB";
            }
            else
            {
                  $filesizet = $filesizekb / 1024;
                  $filesizet = substr($filesizet, 0, 3);
                  $filesizet .= " MB";
            }

            $extType  = substr($file, -1*(strlen($file)-strrpos($file,"."))+1);
            
            $image_src = getIcon($extType);
      
            $filename= $file;
            
            if (strpos($filename, 'FB_')===0)
            {
                  $filename=preg_replace('|^FB_(\d{2})_(\d{2})_(\d{2})_|', 'FB $1/$2/$3 ', $filename);
                  $filename=preg_replace('|^FB_(\d{2})_(\d{2})_(\d{2})|', 'FB $1/$2/$3 ', $filename);
                  $filename=str_replace('_', ' ', $filename);
            }
            
            if (strpos($filename, 'SB_')===0)
            {
                  $filename=preg_replace('|^SB_(\d{2})_(\d{2})_(\d{2})_|', 'SB $1/$2/$3 ', $filename);
                  $filename=preg_replace('|^SB_(\d{2})_(\d{2})_(\d{2})|', 'SB $1/$2/$3 ', $filename);
                  $filename=str_replace('_', ' ', $filename);
            }
                  
            if (!is_dir($file))
            {
                  echo "<tr>\n";
                  echo "<td><img src=\"http://www.dundee.ac.uk/facedusoc/image/".$image_src."\"border='0' title=".$filename."></td><td><a href=\"".$file."\" title='".$filename."'>".$filename."&nbsp;[$filesizet]</a></td>\n";
                  echo "</tr>\n\r";
            }

            if (is_dir($file))
            {
                $rep_file=str_replace('_', '/', $file);
                  echo "<tr>\n";
                  echo "<td><img src=\"http://www.dundee.ac.uk/facedusoc/image/dirIcon.gif\"border='0' title=".$rep_file."></td><td><a href=\"".$file."\" title='".$filename."'>".$rep_file."</a></td>\n";
                  echo "</tr>\n\r";
            }
      }
}

?>

</table><br/>

<table border="0" cellspadding="0" cellspacing="0" id="content">

<tr>
<td align="right"><a href="http://www.dundee.ac.uk/facedusoc" title="faculty office">faculty office</a>&nbsp;|&nbsp;<a href="http://www.dundee.ac.uk/facedusoc/facultyBoard" title="faculty board">faculty board</a>&nbsp;|&nbsp;<a href="javaScript: history.back()" title="back">back</a></td>
</tr>

</table>


</body>

</html>

I want to put the server side includes inside the php document.  Can someone tell me how to do this.

Thanks
0
rossh1977
Asked:
rossh1977
  • 3
  • 3
  • 2
  • +1
1 Solution
 
minichickenCommented:
0
 
Marcus BointonCommented:
minichicken is partly right about using require and include, though note that they're not functions, so you don't have to put the path name in parentheses (and use single quotes for speed).

however, there's an additional feature of virtual: it makes a separate HTTP request for the resource (this is what makes it different from a regular SSI include), and PHP's include/requrie won't do that unless you give it an absolute URL to the resource, so you'd need to use virtual() instead to get a direct equivalent of the SSI function.

Also, what are the double slashes meant to achieve in this?

include("facedusoc//include//functions.php");
0
 
hernst42Commented:
use include for this case:
<!--#include virtual="/ssi/header-with-search.htm"-->

will be
<?php include $_SERVER['DOCUMENT_ROOT'] . "/ssi/header-with-search.htm"; ?>
in php

You might get a problem with the <!--#set var="titleimage" value="/images/titles/heed.gif" --> as those variable will not be replace in that file you include.
Can you post an example of that /ssi/header-with-search.htm so we can see how that variable is used there and how it can be replaced by php in that include.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rossh1977Author Commented:
Hi here's the header-with-search.htm

Not created or maintained by myself:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><LINK
href="header-with-search_files/style2004.css" type=text/css rel=stylesheet>
<SCRIPT language=JavaScript1.2 type=text/javascript>
<!-- hide
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// stop hiding -->
</SCRIPT>

<META content="MSHTML 6.00.2800.1458" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<SCRIPT language=JavaScript type=text/javascript>
  <!-- hide
  if (document.images) {
  uodc_r4_c2_f2 = new Image(26 ,28); uodc_r4_c2_f2.src = "/images/nav/uodc_r4_c2_f2.gif";
  uodc_r4_c2_f1 = new Image(26 ,28); uodc_r4_c2_f1.src = "/images/nav/uodc_r4_c2.gif";
  uodc_r4_c4_f2 = new Image(22 ,28); uodc_r4_c4_f2.src = "/images/nav/uodc_r4_c4_f2.gif";
  uodc_r4_c4_f1 = new Image(22 ,28); uodc_r4_c4_f1.src = "/images/nav/uodc_r4_c4.gif";
  uodc_r4_c6_f2 = new Image(20 ,28); uodc_r4_c6_f2.src = "/images/nav/uodc_r4_c6_f2.gif";
  uodc_r4_c6_f1 = new Image(20 ,28); uodc_r4_c6_f1.src = "/images/nav/uodc_r4_c6.gif";
  uodc_r4_c8_f2 = new Image(35 ,28); uodc_r4_c8_f2.src = "/images/nav/uodc_r4_c8_f2.gif";
  uodc_r4_c8_f1 = new Image(35 ,28); uodc_r4_c8_f1.src = "/images/nav/uodc_r4_c8.gif";
  uodc_r3_c12_f2 = new Image(91 ,30); uodc_r3_c12_f2.src = "/images/nav/uodc_r3_c12_f2.gif";
  uodc_r3_c12_f1 = new Image(91 ,30); uodc_r3_c12_f1.src = "/images/nav/uodc_r3_c12.gif";
  uodc_r3_c14_f2 = new Image(57 ,30); uodc_r3_c14_f2.src = "/images/nav/uodc_r3_c14_f2.gif";
  uodc_r3_c14_f1 = new Image(57 ,30); uodc_r3_c14_f1.src = "/images/nav/uodc_r3_c14.gif";
  uodc_r3_c16_f2 = new Image(61 ,30); uodc_r3_c16_f2.src = "/images/nav/uodc_r3_c16_f2.gif";
  uodc_r3_c16_f1 = new Image(61 ,30); uodc_r3_c16_f1.src = "/images/nav/uodc_r3_c16.gif";
  uodc_r3_c18_f2 = new Image(64 ,30); uodc_r3_c18_f2.src = "/images/nav/uodc_r3_c18_f2.gif";
  uodc_r3_c18_f1 = new Image(64 ,30); uodc_r3_c18_f1.src = "/images/nav/uodc_r3_c18.gif";
  uodc_r3_c20_f2 = new Image(60 ,30); uodc_r3_c20_f2.src = "/images/nav/uodc_r3_c20_f2.gif";
  uodc_r3_c20_f1 = new Image(60 ,30); uodc_r3_c20_f1.src = "/images/nav/uodc_r3_c20.gif";
  }
  // stop hiding -->
  </SCRIPT>

<TABLE cellSpacing=0 cellPadding=0 width=700 border=0><!-- fwtable fwsrc="uodccopy.png" fwbase="uodc.gif" fwstyle="Generic" fwdocid = "742308039" fwnested="1" -->
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=0 width=143 border=0>
        <TBODY>
        <TR>
          <TD><A href="#"><IMG id=uodc_r1_c1 height=101
            alt="University of Dundee"
            src="header-with-search_files/uodc_r1_c1.gif" width=143 border=0
            name=uodc_r1_c1></A></TD></TR>
        <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=0 width=143 border=0>
              <TBODY>
              <TR>
                <TD><IMG id=uodc_r4_c1 height=28 alt=""
                  src="header-with-search_files/uodc_r4_c1.gif" width=5
                border=0></TD>
                <TD><A
                  onmouseover="MM_swapImage('uodc_r4_c2','','/images/nav/uodc_r4_c2_f2.gif',1);"
                  accessKey=1 onmouseout=MM_swapImgRestore();
                  href=""><IMG id=uodc_r4_c2 height=28
                  alt="University Home"
                  src="header-with-search_files/uodc_r4_c2.gif" width=26
                  border=0></A></TD>
                <TD><IMG id=uodc_r4_c3 height=28 alt=""
                  src="header-with-search_files/uodc_r4_c3.gif" width=9
                border=0></TD>
                <TD><A
                  onmouseover="MM_swapImage('uodc_r4_c4','','/images/nav/uodc_r4_c4_f2.gif',1);"
                  accessKey=4 onmouseout=MM_swapImgRestore();
                  href="#"><IMG id=uodc_r4_c4
                  height=28 alt="Search Centre"
                  src="header-with-search_files/uodc_r4_c4.gif" width=22
                  border=0></A></TD>
                <TD><IMG id=uodc_r4_c5 height=28 alt=""
                  src="header-with-search_files/uodc_r4_c5.gif" width=10
                  border=0></TD>
                <TD><A
                  onmouseover="MM_swapImage('uodc_r4_c6','','/images/nav/uodc_r4_c6_f2.gif',1);"
                  accessKey=9 onmouseout=MM_swapImgRestore();
                  href="#"><IMG
                  id=uodc_r4_c6 height=28 alt="Contact Us"
                  src="header-with-search_files/uodc_r4_c6.gif" width=20
                  border=0></A></TD>
                <TD><IMG id=uodc_r4_c7 height=28 alt=""
                  src="header-with-search_files/uodc_r4_c7.gif" width=10
                  border=0></TD>
                <TD><A
                  onmouseover="MM_swapImage('uodc_r4_c8','','/images/nav/uodc_r4_c8_f2.gif',1);"
                  accessKey=3 onmouseout=MM_swapImgRestore();
                  href="#"><IMG
                  id=uodc_r4_c8 height=28 alt="A to Z Index"
                  src="header-with-search_files/uodc_r4_c8.gif" width=35
                  border=0></A></TD>
                <TD><IMG id=uodc_r4_c9 height=28 alt=""
                  src="header-with-search_files/uodc_r4_c9.gif" width=6
                border=0></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>
    <TD><IMG id=uodc_r1_c10 height=129 alt=""
      src="header-with-search_files/uodc_r1_c10.gif" width=5 border=0
      name=uodc_r1_c10></TD>
    <TD>
      <TABLE cellSpacing=0 cellPadding=0 width=552 border=0>
        <TBODY>
        <TR>
          <TD vAlign=top noWrap align=right height=36><A class=nav accessKey=2
            href="#"><IMG
            alt="skip to main page content"
            src="header-with-search_files/spacer.gif" border=0></A><A class=nav
            accessKey=0
            href="#">access
            keys</A> | <A class=nav accessKey=6
            href="/cgi-bin/parser.pl">text
          only</A>&nbsp;</TD></TR>
        <TR>
          <TD><IMG height=43 alt="" src="" width=552 border=0></TD></TR>
        <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=0 width=552 border=0>
              <TBODY>
              <TR>
                <TD><IMG id=uodc_r3_c11 height=30 alt=""
                  src="header-with-search_files/uodc_r3_c11.gif" width=62
                  border=0 name=uodc_r3_c11></TD>
                <TD><A
                  onmouseover="MM_swapImage('uodc_r3_c12','','/images/nav/uodc_r3_c12_f2.gif',1);"
                  onmouseout=MM_swapImgRestore();
                  href="/main/depts.htm"><IMG
                  id=uodc_r3_c12 height=30 alt=Departments
                  src="header-with-search_files/uodc_r3_c12.gif" width=91
                  border=0 name=uodc_r3_c12></A></TD>
                <TD><IMG id=uodc_r3_c13 height=30 alt=""
                  src="header-with-search_files/uodc_r3_c13.gif" width=27
                  border=0 name=uodc_r3_c13></TD>
                <TD><A
                  onmouseover="MM_swapImage('uodc_r3_c14','','/images/nav/uodc_r3_c14_f2.gif',1);"
                  onmouseout=MM_swapImgRestore();
                  href="/main/courses.htm"><IMG
                  id=uodc_r3_c14 height=30 alt=Courses
                  src="header-with-search_files/uodc_r3_c14.gif" width=57
                  border=0 name=uodc_r3_c14></A></TD>
                <TD><IMG id=uodc_r3_c15 height=30 alt=""
                  src="header-with-search_files/uodc_r3_c15.gif" width=25
                  border=0 name=uodc_r3_c15></TD>
                <TD><A
                  onmouseover="MM_swapImage('uodc_r3_c16','','/images/nav/uodc_r3_c16_f2.gif',1);"
                  onmouseout=MM_swapImgRestore();
                  href="/main/facilities.htm"><IMG
                  id=uodc_r3_c16 height=30 alt=Facilities
                  src="header-with-search_files/uodc_r3_c16.gif" width=61
                  border=0 name=uodc_r3_c16></A></TD>
                <TD><IMG id=uodc_r3_c17 height=30 alt=""
                  src="header-with-search_files/uodc_r3_c17.gif" width=21
                  border=0 name=uodc_r3_c17></TD>
                <TD><A
                  onmouseover="MM_swapImage('uodc_r3_c18','','/images/nav/uodc_r3_c18_f2.gif',1);"
                  onmouseout=MM_swapImgRestore();
                  href="/main/research.htm"><IMG
                  id=uodc_r3_c18 height=30 alt=Research
                  src="header-with-search_files/uodc_r3_c18.gif" width=64
                  border=0 name=uodc_r3_c18></A></TD>
                <TD><IMG id=uodc_r3_c19 height=30 alt=""
                  src="header-with-search_files/uodc_r3_c19.gif" width=19
                  border=0 name=uodc_r3_c19></TD>
                <TD><A
                  onmouseover="MM_swapImage('uodc_r3_c20','','/images/nav/uodc_r3_c20_f2.gif',1);"
                  onmouseout=MM_swapImgRestore();
                  href="/main/services.htm"><IMG
                  id=uodc_r3_c20 height=30 alt=Services
                  src="header-with-search_files/uodc_r3_c20.gif" width=60
                  border=0 name=uodc_r3_c20></A></TD>
                <TD><IMG id=uodc_r3_c21 height=30 alt=""
                  src="header-with-search_files/uodc_r3_c21.gif" width=65
                  border=0 name=uodc_r3_c21></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD><IMG id=uodc_r5_c11 height=20 alt=""
            src="header-with-search_files/uodc_r5_c11.gif" width=552 border=0
            name=uodc_r5_c11></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD vAlign=top></TR></TBODY></TABLE></BODY></HTML>

Thanks

Ross

Newbie with php, think i got the // from a tutorial, realise you don't need it, i actually removed them all but not this one.

Cheers

Ross
0
 
hernst42Commented:
ok in that SSI-included parts there are no additional SSI-commands/includes so you can use the
<?php include ... ?> as described.
0
 
rossh1977Author Commented:
Hi i'm still having bother with the <!--#set var="titleimage" value="/images/titles/heed.gif" -->  This sets an img tag to the heed.gif graphic which is the title of the htm document.

Is their anyway of getting this to work how it is

On the generated page it displays:-

<img src="<!--#echo var="titleimage"-->" width="552" height="43" border="0" alt="" />

Which obviously displays an width.. on the screen, but the titleimage is being set by the above, only it doesn't work with the php.  I can change the file that contains <img src="<!--#echo var="titleimage"-->" width="552" height="43" border="0" alt="" /> either.

Thanks

Ross
0
 
Marcus BointonCommented:
As i said, use virtual() instead of include; it will give the server the chance to interpret the SSI stuff before it gets to PHP, otherwise you'll have to emulate everything that SSI does for you, and that's just a waste of time.
0
 
rossh1977Author Commented:
Hi i've tried:-

virtual ( "set var='titleimage' value='/images/titles/heed.gif'");

but it still not working.  Is that the correct syntax?

0
 
Marcus BointonCommented:
No. You're trying to emulate SSI in PHP - don't do it. You must pass a URL into virtual.

Virtual() in PHP works a bit like include, except that it uses an HTTP request to get the file instead of just opening it directly from the file system. This allows the server to do whatever pre-processing would normally be done on the file, which might include SSI processing. PHP has no idea what to do with SSI directives, so all you can do is ask the server to handle it for you. The trap you've got yourself into is that you have SSI and PHP in the same file, which is pretty much asking for trouble - typically if it's a .shtml it will be processed by SSI, and a .php file will be processed by PHP, but doing both at once is difficult and has performance implications. I'd suggest you divide them into separate files, one .shtml, one .php, then include the SSI file from PHP using virtual(). That way your PHP will run, and all SSI pre-processing will be done by the server before it's given to PHP, i.e. PHP will never see the SSI tags, only the results of their interpretation.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now