Zoom Search FAQ - Headers & Footers, SSI & wrapping scripts

Q. How can I add headers & footers to the search template using server side includes (SSIs) or scripts?
Q. How can I add server-side scripting (eg. PHP, ASP) to the search template?

You can not insert SSI or server-side scripting (eg. ASP or PHP) within the "search_template.html" file itself. However, there are a number of ways to essentially achieve the same thing, and produce server-side generated layout for your search page.

First, you should create a custom search page as either a SHTML, PHP or ASP file (eg. "mysearch.php"). This will contain the main layout of your page with the necessary #include for headers, footers, etc. Within this new page, you can embed the Zoom search script, just as you would with a header HTML file. Below are a few examples that demonstrate this.

If you are using the CGI version, you should refer to the following section.

An example using SSI (eg. "mysearch.shtml") with the PHP search script:

<!--#include virtual="header.html" -->
Welcome to my search page
<!--#include virtual="search.php?${QUERY_STRING}" -->
...
<!--#include virtual="footer.html" -->

An example using PHP (eg. "mysearch.php") using include() or virtual():

<?php virtual("header.html"); ?>
Welcome to my search page
<?php virtual("search.php"); ?>
...
<?php virtual("footer.php"); ?>

An example using ASP (eg. "mysearch.asp") and #include:

<!--#include file="header.html"-->
Welcome to my search page
<!--#include file="search.asp"-->
...
<!--#include file="footer.html"-->

This essentially allows you to embed the search results in your own custom search page, with full use of server-side includes for headers and footers, as well as any other scripting capabilities. Once you have done the above, you should be able to see a search form on your new search page ("mysearch.php") when you load it up in a browser.

However, there are a few extra steps before this will work completely:

  • Change the contents of "search_template.html" appropriately (since the output of the search script ("search.php" or "search.asp") now begins in the middle of another script (your custom "mysearch.php" file). For example, you would probably not need another set of <html> or <head> tags.
  • Specify the "LinkBack URL" setting in the indexer configuration window (under the "Advanced" tab). This will allow links generated by the search script (eg. for "Next page of results", etc.) to point to your custom search page, rather than the original search script. For example, if you have included the above code in "mysearch.asp", then you specify "mysearch.asp" as your LinkBack URL.
  • Check the "Disable charset enforcing on search script" option in the Advanced tab of the Configuration window. This is no longer possible since HTML is being displayed before the search script begins to output.
  • If you have search forms placed elsewhere on your website which was previously pointing to "search.php" (or "search.asp", etc.) then you will need to update their action= attribute to point them to your new search page (e.g. "mysearch.php").

You should now have a functioning search page with your own SSI for headers, footers, etc.

An alternative to the above, is to edit "search.php" or "search.asp" to perform the include function in place of the SSI. That is, instead of using SSI in the search_template.html, you make the include within the search script itself. This requires familiarity with the PHP or ASP scripting language. For PHP, you can use the include() or virtual() functions. ASP users will need to use the #include directive. Most of the time, these changes should only need to be made at the top or bottom of the existing search script.

Another possibility is to configure your webserver to handle the file extension for SSI. However, most web-servers default settings do not allow a file extension to be handled by an external interpreter and parsed internally for SSIs.

Q. How do I use SSI or server-side scripting with the CGI version?

Since the CGI version is a binary executable, it can not be edited like the PHP or ASP search scripts. However, you can "embed" the CGI into your own SHTML, PHP, ASP or ColdFusion file. This means that your SHTML/PHP/ASP/CF file will have to call the CGI and pass the parameters along appropriately. Below are some examples of how to do this for each respective language.

To call the search.cgi file from a SHTML (server-side HTML) file, use the following:

<!--#include virtual="/cgi-bin/search.cgi?${QUERY_STRING}" -->

Note that the above only works on an Apache server. There is no known equivalent method for use with SHTML files on IIS servers. For IIS users, we would recommend the ASP method further below.

To embed search.cgi within a PHP file on an Apache server, use the following code (replacing the path to the search.cgi as appropriate):

<?php
$QSTRING = $_SERVER['QUERY_STRING'];
virtual("/cgi-bin/search.cgi".'?'.$QSTRING);
?>

To embed search.cgi within a PHP file on an IIS server, you would need to use the following code instead:

<?php
$QSTRING = $_SERVER['QUERY_STRING'];
$REMADDR = $_SERVER['REMOTE_ADDR'];
putenv("REQUEST_METHOD=GET");
putenv("QUERY_STRING=$QSTRING");
putenv("REMOTE_ADDR=$REMADDR");
// absolute path to search.cgi required below
$output = shell_exec("C:\\Inetpub\\wwwroot\\zoom\\search.cgi");
$output = ereg_replace("Content-type: text/html", "", $output);
echo $output;
?>

Note that for shell_exec to work, the IIS guest account (IUSR_***) may require read/execute permissions on "c:\windows\system32\cmd.exe" and the "search.cgi". These permission instruction relate to IIS 6 on Windows Server 2003 and may vary depending on existing security policies and different versions of IIS and Windows.

To embed search.cgi within an ASP file, use the following code on your ASP page (make sure you have at least WScript 5.6 installed on your web server):

<%
Dim WshShell, env, oExec
Set WshShell = CreateObject("WScript.Shell")
Set env = WshShell.Environment("Process")
env.Item("REQUEST_METHOD") = "GET"
env.Item("QUERY_STRING") = Request.QueryString
env.Item("REMOTE_ADDR") = Request.ServerVariables("REMOTE_ADDR")
set oExec = WshShell.Exec(Server.MapPath("search.cgi"))
oExec.StdOut.ReadLine() ' skip the HTTP header line
Response.Write(oExec.StdOut.ReadAll())
%>

To embed search.cgi within an ColdFusion file, you can use the following code (thanks go to one of our kind users, Amy Adler, for this contribution) on your CF page:

<cfhttp url="search.cgi?#CGI.QUERY_STRING#" method="GET" timeout="10" throwOnError="yes">
<!--- display search results --->
<cfif IsDefined("CFHTTP.FileContent")>
<cfoutput>#CFHTTP.FileContent#</cfoutput>
</cfif>

You will also have to:

  • Change the contents of "search_template.html" appropriately (since the output of the CGI is now within your PHP or ASP file, you probably would not need another set of <html> or <head> tags)
  • Specify the "LinkBack URL" setting in the indexer configuration window (under the "Advanced" tab). This will allow links generated by the CGI (eg. for "Next page of results", etc.) to point to the file where you have pasted the above code, rather than the CGI itself. For example, if you have included the above code in "mysearch.asp", then you specify "mysearch.asp" as your LinkBack URL.
  • Check the "Disable charset enforcing on search script" option in the Advanced tab of the Configuration window. This is no longer possible since HTML is being displayed before the search script begins to output.

You should now have a functioning search page with your own SSI for headers, footers, etc.

Return to the Zoom Search Engine Support page