Search This! - Performing the Search (
Page 5 of 6 )
ht://Dig is
normally run as a CGI script ("normally" meaning "by everyone who doesn't use
PHP3!"). To run the search program from PHP, you will need a file called
htdig.sh which looks like this:
#!/bin/sh
HTBINDIR=/usr/local/htdocs/htdig/cgi-bin
QUERY_STRING="$@"
REQUEST_METHOD=GET
export QUERY_STRING REQUEST_METHOD
$HTBINDIR/htsearch
Just change the value of HTBINDIR to whatever is appropriate for
your setup (i.e. the path you picked for CGIBIN_DIR in the
CONFIG file when you installed ht://Dig).
I recommend putting this file in the search/ subdirectory as
well, along with the template files. You also need to change file permissions so
htdig.sh is executable by your web server.
Next, we need to get PHP to talk to the search script. Finally, some PHP
code! This is simply a matter of building the query string to pass to
htdig.sh, executing the search, and parsing the results.
So, in results.php3, we build the query string:
<?php
$HTSEARCH_PROG = "/www/summerworks/search/htdig.sh";
$words = EscapeShellCmd(UrlEncode($search));
$config = "sw98";
$format = "sw98";
$query = "config=$config&format=$format&words=$words";
?>
$HTSEARCH_PROG is the location of the
htdig.sh program.
$search is passed from the form, and
is the list of words to search for.
$config tells ht://Dig which
.conf file to use, and
$format tells it which template
map to use from the
.conf file.
Then we run the search:
<?
$command="$HTSEARCH_PROG \"$query\"";
exec($command,$result);
?>
This puts the results of the search into the array $result, which
PHP then parses to display the results.