...

View Full Version : Resolved implementing search script into design



AntiHero118
04-29-2009, 03:05 PM
Hello,

I've scrapped the previous script i was using and am trying another.

I was wondering if someone could please explain to me how I could get this script to submit the results to a second page and not to itself? I've been trying to teach myself PHP from reading the documentation on php.net for some time now, but I'm having a really really hard time.



<?

//Configuration
$my_server = "http://".getenv("SERVER_NAME").":".getenv("SERVER_PORT"); // Your Server (generally no changes needed)
$my_root = getenv("DOCUMENT_ROOT"); // Your document root (generally no changes needed)
$s_dirs = array("/search/dir1","/search/dir2"); // Which directories should be searched ("/dir1","/dir2","/dir1/subdir2","/Verzeichniss2/Unterverzeichniss2")? --> $s_dirs = array(""); searches the entire server
$s_skip = array("..",".","subdir2"); // Which files/dirs do you like to skip?
$s_files = "html|htm|HTM|HTML|php3|php4|php|txt"; // Which files types should be searched? Example: "html$|htm$|php4$"
$min_chars = "3"; // Min. chars that must be entered to perform the search
$max_chars = "30"; // Max. chars that can be submited to perform the search
$default_val = "Searchphrase"; // Default value in searchfield
$limit_hits = array("5","10","25","50","100"); // How many hits should be displayed, to suppress the select-menu simply use one value in the array --> array("100")
$message_1 = "Invalid Searchterm!"; // Invalid searchterm
$message_2 = "Please enter at least '$min_chars', highest '$max_chars' characters."; // Invalid searchterm long ($min_chars/$max_chars)
$message_3= "Your searchresult for:"; // Headline searchresults
$message_4 = "Sorry, no hits."; // No hits
$message_5 = "results"; // Hits
$message_6 = "Match case"; // Match case
$no_title = "Untiteled"; // This should be displayed if no title or empty title is found in file
$limit_extracts_extracts = ""; // How many extratcts per file do you like to display. Default: "" --> every extract, alternative: 'integer' e.g. "3"
$byte_size = "51200"; // How many bytes per file should be searched? Reduce to increase speed

//ini_set("error_reporting", "2047"); // Debugger

// search_form()
function search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6, $PHP_SELF) {
@$keyword=$HTTP_GET_VARS['keyword'];
@$case=$HTTP_GET_VARS['case'];
@$limit=$HTTP_GET_VARS['limit'];
echo
"<form action=\"$PHP_SELF\" method=\"GET\">\n",
"<input type=\"hidden\" value=\"SEARCH\" name=\"action\">\n",
"<input type=\"text\" name=\"keyword\" class=\"text\" size=\"10\" maxlength=\"30\" value=\"";
if(!$keyword)
echo "$default_val";
else
echo str_replace("&amp;","&",htmlentities($keyword));
echo "\" ";
echo "onFocus=\" if (value == '";
if(!$keyword)
echo "$default_val";
else
echo str_replace("&amp;","&",htmlentities($keyword));
echo "') {value=''}\" onBlur=\"if (value == '') {value='";
if(!$keyword)
echo "$default_val";
else
echo str_replace("&amp;","&",htmlentities($keyword));
echo "'}\"> ";
$j=count($limit_hits);
if($j==1)
echo "<input type=\"hidden\" value=\"".$limit_hits[0]."\" name=\"limit\">";
elseif($j>1) {
echo
"<select name=\"limit\" class=\"select\">\n";
for($i=0;$i<$j;$i++) {
echo "<option value=\"".$limit_hits[$i]."\"";
if($limit==$limit_hits[$i])
echo "SELECTED";
echo ">".$limit_hits[$i]." $message_5</option>\n";
}
echo "</select> ";
}
echo
"<input type=\"submit\" value=\"OK\" class=\"button\">\n",
"<br>\n",
"<span class=\"checkbox\">$message_6</span> <input type=\"checkbox\" name=\"case\" value=\"true\" class=\"checkbox\"";
if($case)
echo " CHECKED";
echo
">\n",
"<br>\n",
"<a href=\"http://www.terraserver.de/\" class=\"ts\" target=\"_blank\">Powered by terraserver.de/search</a>",
"</form>\n";
}


// search_headline()
function search_headline($HTTP_GET_VARS, $message_3) {
@$keyword=$HTTP_GET_VARS['keyword'];
@$action=$HTTP_GET_VARS['action'];
if($action == "SEARCH") // Volltextsuche
echo "<h1 class=\"result\">$message_3 '<i>".htmlentities(stripslashes($keyword))."</i>'</h1>";
}


// search_error()
function search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits) {
global $HTTP_GET_VARS;
@$keyword=$HTTP_GET_VARS['keyword'];
@$action=$HTTP_GET_VARS['action'];
@$limit=$HTTP_GET_VARS['limit'];
if($action == "SEARCH") { // Volltextsuche
if(strlen($keyword)<$min_chars||strlen($keyword)>$max_chars||!in_array ($limit, $limit_hits)) { // Ist die Anfrage in Ordnung (min. '$min_chars' Zeichen, max. '$max_chars' Zeichen)?
echo "<p class=\"result\"><b>$message_1</b><br>$message_2</p>";
$HTTP_GET_VARS['action'] = "ERROR"; // Suche abbrechen
}
}
}


// search_dir(): Volltextsuche in Verzeichnissen
function search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS) {
global $count_hits;
@$keyword=$HTTP_GET_VARS['keyword'];
@$action=$HTTP_GET_VARS['action'];
@$limit=$HTTP_GET_VARS['limit'];
@$case=$HTTP_GET_VARS['case'];
if($action == "SEARCH") { // Volltextsuche
foreach($s_dirs as $dir) { // Alle Verzeichnisse in $s_dirs durchsuchen
$handle = @opendir($my_root.$dir);
while($file = @readdir($handle)) {
if(in_array($file, $s_skip)) { // Alles in $skip auslassen
continue;
}
elseif($count_hits>=$limit) {
break; // Maximale Trefferzahl erreicht
}
elseif(is_dir($my_root.$dir."/".$file)) { // Unterverzeichnisse durchsuchen
$s_dirs = array("$dir/$file");
search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS); // search_dir() rekursiv auf alle Unterverzeichnisse aufrufen
}
elseif(preg_match("/($s_files)$/i", $file)) { // Alle Dateien gemaess Endungen $s_files
$fd=fopen($my_root.$dir."/".$file,"r");
$text=fread($fd, $byte_size); // 50 KB
$keyword_html = htmlentities($keyword);
if($case) { // Gross-/Kleinschreibung beruecksichtigen?
$do=strstr($text, $keyword)||strstr($text, $keyword_html);
}
else {
$do=stristr($text, $keyword)||stristr($text, $keyword_html);
}
if($do) {
$count_hits++; // Treffer zaehlen
if(preg_match_all("=<title[^>]*>(.*)</title>=siU", $text, $titel)) { // Generierung des Link-Textets aus <title>...</title>
if(!$titel[1][0]) // <title></title> ist leer...
$link_title=$no_title; // ...also $no_title
else
$link_title=$titel[1][0]; // <title>...</title> vorhanden...
}
else {
$link_title=$no_title; // ...ansonsten $no_title
}
echo "<a href=\"$my_server$dir/$file\" target=\"_self\" class=\"result\">$count_hits. $link_title</a><br>"; // Ausgabe des Links
$auszug = strip_tags($text);
$keyword = preg_quote($keyword); // unescapen
$keyword = str_replace("/","\/","$keyword");
$keyword_html = preg_quote($keyword_html); // unescapen
$keyword_html = str_replace("/","\/","$keyword_html");
echo "<span class=\"extract\">";
if(preg_match_all("/((\s\S*){0,3})($keyword|$keyword_html)((\s?\S*){0,3})/i", $auszug, $match, PREG_SET_ORDER)); {
if(!$limit_extracts)
$number=count($match);
else
$number=$limit_extracts;
for ($h=0;$h<$number;$h++) { // Kein Limit angegeben also alle Vorkommen ausgeben
if (!empty($match[$h][3]))
printf("<i><b>..</b> %s<b>%s</b>%s <b>..</b></i>", $match[$h][1], $match[$h][3], $match[$h][4]);
}
}
echo "</span><br><br>";
flush();
}
fclose($fd);
}
}
@closedir($handle);
}
}
}


// search_no_hits(): Ausgabe 'keine Treffer' bei der Suche
function search_no_hits($HTTP_GET_VARS, $count_hits, $message_4) {
@$action=$HTTP_GET_VARS['action'];
if($action == "SEARCH" && $count_hits<1) // Volltextsuche, kein Treffer
echo "<p class=\"result\">$message_4</p>";
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<style type="text/css">
<!--
input.text {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : normal;
font-size : 12px;
text-decoration : none;
width : 120px;
}

input.button {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : normal;
font-size : 12px;
text-decoration : none;
}

input.checkbox {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : normal;
font-size : 12px;
text-decoration : none;
}

span.checkbox {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : normal;
font-size : 11px;
text-decoration : none;
}

select.select {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : normal;
font-size : 12px;
text-decoration : none;
}

h1.result {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : bold;
font-size : 14px;
text-decoration : none;
}

p.result {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : normal;
font-size : 12px;
text-decoration : none;
}

a.result:link {
font-family : verdana, arial,helvetica,sans-serif;
color : #03629C;
font-weight : bold;
font-size : 12px;
text-decoration : none;
}

a.result:visited {
font-family : verdana, arial,helvetica,sans-serif;
color : #03629C;
font-weight : bold;
font-size : 12px;
text-decoration : none;
}

a.result:active {
font-family : verdana, arial,helvetica,sans-serif;
color : #9D9D9D;
font-weight : bold;
font-size : 12px;
text-decoration : underline;
}

a.result:hover {
font-family : verdana, arial,helvetica,sans-serif;
color : #9D9D9D;
font-weight : bold;
font-size : 12px;
text-decoration : underline;
}

span.extract {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : normal;
font-size : 11px;
text-decoration : none;
}

a.ts:link {
font-family : verdana, arial,helvetica,sans-serif;
color : #03629C;
font-weight : normal;
font-size : 9px;
text-decoration : none;
}

a.ts:visited {
font-family : verdana, arial,helvetica,sans-serif;
color : #03629C;
font-weight : normal;
font-size : 9px;
text-decoration : none;
}

a.ts:active {
font-family : verdana, arial,helvetica,sans-serif;
color : #9D9D9D;
font-weight : normal;
font-size : 9px;
text-decoration : underline;
}

a.ts:hover {
font-family : verdana, arial,helvetica,sans-serif;
color : #9D9D9D;
font-weight : normal;
font-size : 9px;
text-decoration : underline;
}
//-->
</style>
<title>terraserver.de/search</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#03629C" vlink="#03629C" alink="#9D9D9D">
<table border="0" cellspacing="1" cellpadding="0" bgcolor="#03629C">
<tr align="left" valign="top">
<td>
<table border="0" cellspacing="0" cellpadding="3" bgcolor="#FFFFFF">
<tr align="left" valign="top">
<td>
<?
// search_form(): Gibt das Suchformular aus
search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6, $PHP_SELF);
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
// search_headline(): Ueberschrift Suchergebnisse
search_headline($HTTP_GET_VARS, $message_3);
// search_error(): Auf Fehler testen und Suchfehler anzeigen
search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits);
// search_dir(): Volltextsuche in Verzeichnissen (siehe config.php4)
search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS);
// search_no_hits(): Ausgabe 'keine Treffer' bei der Suche
search_no_hits($HTTP_GET_VARS, $count_hits, $message_4);
?>
</body>
</html>



Please help, I'm really stuck here.

Thanks

AntiHero118
04-29-2009, 05:06 PM
Ignore this message, see above.

Eldarrion
04-29-2009, 06:44 PM
As far as I know, PHP can't submit data on its own. Either you're going to need to use a form to submit to another file or use JavaScript to do an Ajax request. Other than that, you can include the secondary file, but in that case it will run as a child process to the primary file rather than having the information be submitted. One question that arises in this case though is... why would you want to submit information from one PHP script to another?

AntiHero118
04-29-2009, 07:09 PM
I'm trying to get it to submit to search.php and display the results of the query. but thus far all I can get it to do is print an array on the search page.



<?

//Configuration
$my_server = "http://".getenv("SERVER_NAME").":".getenv("SERVER_PORT"); // Your Server (generally no changes needed)
$my_root = getenv("DOCUMENT_ROOT"); // Your document root (generally no changes needed)
$s_dirs = array("/"); // Which directories should be searched ("/dir1","/dir2","/dir1/subdir2","/Verzeichniss2/Unterverzeichniss2")? --> $s_dirs = array(""); searches the entire server
$s_skip = array("..","."); // Which files/dirs do you like to skip?
$s_files = "html|htm|HTM|HTML|php3|php4|php|txt"; // Which files types should be searched? Example: "html$|htm$|php4$"
$min_chars = "3"; // Min. chars that must be entered to perform the search
$max_chars = "30"; // Max. chars that can be submited to perform the search
$default_val = "Search..."; // Default value in searchfield
$limit_hits = array("10"); // How many hits should be displayed, to suppress the select-menu simply use one value in the array --> array("100")
$message_1 = "Invalid Search term!"; // Invalid searchterm
$message_2 = "Please enter at least '$min_chars', highest '$max_chars' characters."; // Invalid searchterm long ($min_chars/$max_chars)
$message_3= "Your search result for:"; // Headline searchresults
$message_4 = "Sorry, no hits."; // No hits
$message_5 = "Results"; // Hits
$message_6 = "Match case"; // Match case
$no_title = "Untitled"; // This should be displayed if no title or empty title is found in file
$limit_extracts_extracts = ""; // How many extratcts per file do you like to display. Default: "" --> every extract, alternative: 'integer' e.g. "3"
$byte_size = "51200"; // How many bytes per file should be searched? Reduce to increase speed

//ini_set("error_reporting", "2047"); // Debugger

// search_form()
function search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6) {
@$keyword=$HTTP_GET_VARS['keyword'];
@$case=$HTTP_GET_VARS['case'];
@$limit=$HTTP_GET_VARS['limit'];
echo
"<form action=\"search.php\" method=\"POST\">\n",
"<input type=\"hidden\" value=\"SEARCH\" name=\"action\">\n",
"<input type=\"text\" name=\"keyword\" class=\"text\" size=\"10\" maxlength=\"30\" value=\"";
if(!$keyword)
echo "$default_val";
else
echo str_replace("&amp;","&",htmlentities($keyword));
echo "\" ";
echo "onFocus=\" if (value == '";
if(!$keyword)
echo "$default_val";
else
echo str_replace("&amp;","&",htmlentities($keyword));
echo "') {value=''}\" onBlur=\"if (value == '') {value='";
if(!$keyword)
echo "$default_val";
else
echo str_replace("&amp;","&",htmlentities($keyword));
echo "'}\"> ";
$j=count($limit_hits);
if($j==1)
echo "<input type=\"hidden\" value=\"".$limit_hits[0]."\" name=\"limit\">";
elseif($j>1) {
echo
"<select name=\"limit\" class=\"select\">\n";
for($i=0;$i<$j;$i++) {
echo "<option value=\"".$limit_hits[$i]."\"";
if($limit==$limit_hits[$i])
echo "SELECTED";
echo ">".$limit_hits[$i]." $message_5</option>\n";
}
echo "</select> ";
}
echo
"<input type=\"image\" src=\"images/buttons/search.png\" value=\"OK\" class=\"button\">\n",
"<br>\n",
"</form>\n";
}


// search_headline()
function search_headline($HTTP_GET_VARS, $message_3) {
@$keyword=$HTTP_GET_VARS['keyword'];
@$action=$HTTP_GET_VARS['action'];
if($action == "SEARCH") // Volltextsuche
echo "<h1 class=\"result\">$message_3 '<i>".htmlentities(stripslashes($keyword))."</i>'</h1>";
}


// search_error()
function search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits) {
global $HTTP_GET_VARS;
@$keyword=$HTTP_GET_VARS['keyword'];
@$action=$HTTP_GET_VARS['action'];
@$limit=$HTTP_GET_VARS['limit'];
if($action == "SEARCH") { // Volltextsuche
if(strlen($keyword)<$min_chars||strlen($keyword)>$max_chars||!in_array ($limit, $limit_hits)) { // Ist die Anfrage in Ordnung (min. '$min_chars' Zeichen, max. '$max_chars' Zeichen)?
echo "<p class=\"result\"><b>$message_1</b><br>$message_2</p>";
$HTTP_GET_VARS['action'] = "ERROR"; // Suche abbrechen
}
}
}


// search_dir(): Volltextsuche in Verzeichnissen
function search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS) {
global $count_hits;
@$keyword=$HTTP_GET_VARS['keyword'];
@$action=$HTTP_GET_VARS['action'];
@$limit=$HTTP_GET_VARS['limit'];
@$case=$HTTP_GET_VARS['case'];
if($action == "SEARCH") { // Volltextsuche
foreach($s_dirs as $dir) { // Alle Verzeichnisse in $s_dirs durchsuchen
$handle = @opendir($my_root.$dir);
while($file = @readdir($handle)) {
if(in_array($file, $s_skip)) { // Alles in $skip auslassen
continue;
}
elseif($count_hits>=$limit) {
break; // Maximale Trefferzahl erreicht
}
elseif(is_dir($my_root.$dir."/".$file)) { // Unterverzeichnisse durchsuchen
$s_dirs = array("$dir/$file");
search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS); // search_dir() rekursiv auf alle Unterverzeichnisse aufrufen
}
elseif(preg_match("/($s_files)$/i", $file)) { // Alle Dateien gemaess Endungen $s_files
$fd=fopen($my_root.$dir."/".$file,"r");
$text=fread($fd, $byte_size); // 50 KB
$keyword_html = htmlentities($keyword);
if($case) { // Gross-/Kleinschreibung beruecksichtigen?
$do=strstr($text, $keyword)||strstr($text, $keyword_html);
}
else {
$do=stristr($text, $keyword)||stristr($text, $keyword_html);
}
if($do) {
$count_hits++; // Treffer zaehlen
if(preg_match_all("=<title[^>]*>(.*)</title>=siU", $text, $titel)) { // Generierung des Link-Textets aus <title>...</title>
if(!$titel[1][0]) // <title></title> ist leer...
$link_title=$no_title; // ...also $no_title
else
$link_title=$titel[1][0]; // <title>...</title> vorhanden...
}
else {
$link_title=$no_title; // ...ansonsten $no_title
}
echo "<a href=\"$my_server$dir/$file\" target=\"_self\" class=\"result\">$count_hits. $link_title</a><br>"; // Ausgabe des Links
$auszug = strip_tags($text);
$keyword = preg_quote($keyword); // unescapen
$keyword = str_replace("/","\/","$keyword");
$keyword_html = preg_quote($keyword_html); // unescapen
$keyword_html = str_replace("/","\/","$keyword_html");
echo "<span class=\"extract\">";
if(preg_match_all("/((\s\S*){0,3})($keyword|$keyword_html)((\s?\S*){0,3})/i", $auszug, $match, PREG_SET_ORDER)); {
if(!$limit_extracts)
$number=count($match);
else
$number=$limit_extracts;
for ($h=0;$h<$number;$h++) { // Kein Limit angegeben also alle Vorkommen ausgeben
if (!empty($match[$h][3]))
printf("<i><b>..</b> %s<b>%s</b>%s <b>..</b></i>", $match[$h][1], $match[$h][3], $match[$h][4]);
}
}
echo "</span><br><br>";
flush();
}
fclose($fd);
}
}
@closedir($handle);
}
}
}


// search_no_hits(): Ausgabe 'keine Treffer' bei der Suche
function search_no_hits($HTTP_GET_VARS, $count_hits, $message_4) {
@$action=$HTTP_GET_VARS['action'];
if($action == "SEARCH" && $count_hits<1) // Volltextsuche, kein Treffer
echo "<p class=\"result\">$message_4</p>";
}

?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Skowhegan Savings Bank | Central Maine Bank</title>
<link href="styles/style.css" rel="stylesheet" type="text/css" />
<link href="styles/nav.css" rel="stylesheet" type="text/css" />
<link href="styles/slideshow.css" rel="stylesheet" type="text/css" />
<style type="text/css">
h1.result {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : bold;
font-size : 14px;
text-decoration : none;
}

p.result {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : normal;
font-size : 12px;
text-decoration : none;
}

a.result:link {
font-family : verdana, arial,helvetica,sans-serif;
color : #03629C;
font-weight : bold;
font-size : 12px;
text-decoration : none;
}

a.result:visited {
font-family : verdana, arial,helvetica,sans-serif;
color : #03629C;
font-weight : bold;
font-size : 12px;
text-decoration : none;
}

a.result:active {
font-family : verdana, arial,helvetica,sans-serif;
color : #9D9D9D;
font-weight : bold;
font-size : 12px;
text-decoration : underline;
}

a.result:hover {
font-family : verdana, arial,helvetica,sans-serif;
color : #9D9D9D;
font-weight : bold;
font-size : 12px;
text-decoration : underline;
}

span.extract {
font-family : verdana, arial,helvetica,sans-serif;
color : #000000;
font-weight : normal;
font-size : 11px;
text-decoration : none;
}

a.ts:link {
font-family : verdana, arial,helvetica,sans-serif;
color : #03629C;
font-weight : normal;
font-size : 9px;
text-decoration : none;
}

a.ts:visited {
font-family : verdana, arial,helvetica,sans-serif;
color : #03629C;
font-weight : normal;
font-size : 9px;
text-decoration : none;
}

a.ts:active {
font-family : verdana, arial,helvetica,sans-serif;
color : #9D9D9D;
font-weight : normal;
font-size : 9px;
text-decoration : underline;
}

a.ts:hover {
font-family : verdana, arial,helvetica,sans-serif;
color : #9D9D9D;
font-weight : normal;
font-size : 9px;
text-decoration : underline;
}
//-->
</style>
<!--[if gt IE 6]>
<link href="styles/ieonly.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script type="text/javascript" src="scripts/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="scripts/slideshow.js"></script>
<script language="JavaScript1.2" type="text/javascript">
<!--
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;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//-->
</script>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><? include('inc_header.php');?></td>
</tr>
</table>
<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" class="table_white">
<tr>
<td><table width="850" border="0" cellpadding="0" cellspacing="0" class="table_white">
<tr>
<td width="197" valign="top"><br />
<? include('inc_onlinebanking.php');?>
<br />
<? include('inc_rates.php');?>
<br />
<? include('inc_contactus.php');?>
<br />
<? include('inc_community.php');?>
<br />
<? include('inc_enewsletter.php');?>
<br />

</td>
<td width="21">&nbsp;</td>
<td><table width="588" border="0" align="left" cellpadding="0" cellspacing="0" class="table_white">
<tr>
<td height="240"><br />
<div id="slideshow"> <img src="images/slideshow/brenda_dyer.jpg" alt="Brenda Dyer - Skowhegan Savings Bank" class="active" /> <img src="images/slideshow/crystal_deck.jpg" alt="Crystal Deck - Skowhegan Savings Bank" /> <img src="images/slideshow/fred_harberberger.jpg" alt="Fred Harberberger - Skowhegan Savings Bank" /> <img src="images/slideshow/jodi_michaud.jpg" alt="Jodi Michaud - Skowhegan Savings Bank" /> <img src="images/slideshow/karen_hart.jpg" alt="Karen Hart - Skowhegan Savings Bank" /> <img src="images/slideshow/rick_whalen.jpg" alt="Rick Whalen - Skowhegan Savings Bank" /></div></td>
</tr>
<tr>
<td height="19" valign="middle" class="text"><div align="center">
<p><br />
Our
mission is to make our communities a better place to live and
work by assuring access <br />
to relevant financial services
and reinvesting in
our communities.<br />
<br />
<br />
</p>
</div></td>
</tr>
<tr>
<td valign="top" class="text"><div id="contents" align="left">
<table width="588" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="167" class="highlight"><strong>Integrity.</strong></td>
<td width="30" rowspan="2" class="vertical_line"><img src="images/site/hightlight_seperator.jpg" width="30" height="100" /></td>
<td width="167" class="highlight"><strong>Trust.</strong></td>
<td width="30" rowspan="2" class="vertical_line"><img src="images/site/hightlight_seperator.jpg" width="30" height="100" /></td>
<td width="167" class="highlight"><strong>Community.</strong></td>
<td width="10" rowspan="2">&nbsp;</td>
</tr>
<tr>
<td width="167" valign="top" class="text"><p>
<br />
Every customer is treated with integrity and respect at Skowhegan Savings. </p>
<p>You can count on us to do what is right for you; when you walk through the doors of any of our branches, our experienced, honest and forthright team of employees will take the time to understand your financial needs and help provide you with solutions.</p>
<p>&nbsp;</p></td>
<td width="167" valign="top" class="text"><p>
<br />
For nearly 140 years, we have helped you make prudent financial decisions in order to achieve your dreams. Skowhegan Savings has been helping generations of Maine families by giving them a safe place to invest. </p>
<p>Now, more than ever, your community bank is your ally during difficult times. The main reason that we are here is to help you: you are not just our customer, you are our friend.</p></td>
<td width="167" class="text"><p>
<br />
Skowhegan Savings is here to help strengthen your community.
Our employees take great pride in serving their communities
and take a leading role in providing financial education
opportunities for the people of the region. </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p> <p>&nbsp;</p></td>
</tr>
</table>
</div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><? include('inc_footer.php');?></td>
</tr>
</table>
<?
// search_headline(): Ueberschrift Suchergebnisse
search_headline($HTTP_GET_VARS, $message_3);
// search_error(): Auf Fehler testen und Suchfehler anzeigen
search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits);
// search_dir(): Volltextsuche in Verzeichnissen (siehe config.php4)
search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS);
// search_no_hits(): Ausgabe 'keine Treffer' bei der Suche
search_no_hits($HTTP_GET_VARS, $count_hits, $message_4);
?>
</body>
</html>


the search box and button are kept in the header and look like this

<? search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6, search.php);?>

AntiHero118
04-29-2009, 07:09 PM
and my search.php page looks like this



<?

//Configuration
$my_server = "http://".getenv("SERVER_NAME").":".getenv("SERVER_PORT"); // Your Server (generally no changes needed)
$my_root = getenv("DOCUMENT_ROOT"); // Your document root (generally no changes needed)
$s_dirs = array("/"); // Which directories should be searched ("/dir1","/dir2","/dir1/subdir2","/Verzeichniss2/Unterverzeichniss2")? --> $s_dirs = array(""); searches the entire server
$s_skip = array("..","."); // Which files/dirs do you like to skip?
$s_files = "html|htm|HTM|HTML|php3|php4|php|txt"; // Which files types should be searched? Example: "html$|htm$|php4$"
$min_chars = "3"; // Min. chars that must be entered to perform the search
$max_chars = "30"; // Max. chars that can be submited to perform the search
$default_val = "Search..."; // Default value in searchfield
$limit_hits = array("10"); // How many hits should be displayed, to suppress the select-menu simply use one value in the array --> array("100")
$message_1 = "Invalid Search term!"; // Invalid searchterm
$message_2 = "Please enter at least '$min_chars', highest '$max_chars' characters."; // Invalid searchterm long ($min_chars/$max_chars)
$message_3= "Your search result for:"; // Headline searchresults
$message_4 = "Sorry, no hits."; // No hits
$message_5 = "Results"; // Hits
$message_6 = "Match case"; // Match case
$no_title = "Untitled"; // This should be displayed if no title or empty title is found in file
$limit_extracts_extracts = ""; // How many extratcts per file do you like to display. Default: "" --> every extract, alternative: 'integer' e.g. "3"
$byte_size = "51200"; // How many bytes per file should be searched? Reduce to increase speed

//ini_set("error_reporting", "2047"); // Debugger

// search_form()
function search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6) {
@$keyword=$HTTP_GET_VARS['keyword'];
@$case=$HTTP_GET_VARS['case'];
@$limit=$HTTP_GET_VARS['limit'];
echo
"<form action=\"search.php\" method=\"POST\">\n",
"<input type=\"hidden\" value=\"SEARCH\" name=\"action\">\n",
"<input type=\"text\" name=\"keyword\" class=\"text\" size=\"10\" maxlength=\"30\" value=\"";
if(!$keyword)
echo "$default_val";
else
echo str_replace("&amp;","&",htmlentities($keyword));
echo "\" ";
echo "onFocus=\" if (value == '";
if(!$keyword)
echo "$default_val";
else
echo str_replace("&amp;","&",htmlentities($keyword));
echo "') {value=''}\" onBlur=\"if (value == '') {value='";
if(!$keyword)
echo "$default_val";
else
echo str_replace("&amp;","&",htmlentities($keyword));
echo "'}\"> ";
$j=count($limit_hits);
if($j==1)
echo "<input type=\"hidden\" value=\"".$limit_hits[0]."\" name=\"limit\">";
elseif($j>1) {
echo
"<select name=\"limit\" class=\"select\">\n";
for($i=0;$i<$j;$i++) {
echo "<option value=\"".$limit_hits[$i]."\"";
if($limit==$limit_hits[$i])
echo "SELECTED";
echo ">".$limit_hits[$i]." $message_5</option>\n";
}
echo "</select> ";
}
echo
"<input type=\"submit\" value=\"OK\" class=\"button\">",
"</form>\n";
}


// search_headline()
function search_headline($HTTP_GET_VARS, $message_3) {
@$keyword=$HTTP_GET_VARS['keyword'];
@$action=$HTTP_GET_VARS['action'];
if($action == "SEARCH") // Volltextsuche
echo "<h1 class=\"result\">$message_3 '<i>".htmlentities(stripslashes($keyword))."</i>'</h1>";
}


// search_error()
function search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits) {
global $HTTP_GET_VARS;
@$keyword=$HTTP_GET_VARS['keyword'];
@$action=$HTTP_GET_VARS['action'];
@$limit=$HTTP_GET_VARS['limit'];
if($action == "SEARCH") { // Volltextsuche
if(strlen($keyword)<$min_chars||strlen($keyword)>$max_chars||!in_array ($limit, $limit_hits)) { // Ist die Anfrage in Ordnung (min. '$min_chars' Zeichen, max. '$max_chars' Zeichen)?
echo "<p class=\"result\"><b>$message_1</b><br>$message_2</p>";
$HTTP_GET_VARS['action'] = "ERROR"; // Suche abbrechen
}
}
}


// search_dir(): Volltextsuche in Verzeichnissen
function search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS) {
global $count_hits;
@$keyword=$HTTP_GET_VARS['keyword'];
@$action=$HTTP_GET_VARS['action'];
@$limit=$HTTP_GET_VARS['limit'];
@$case=$HTTP_GET_VARS['case'];
if($action == "SEARCH") { // Volltextsuche
foreach($s_dirs as $dir) { // Alle Verzeichnisse in $s_dirs durchsuchen
$handle = @opendir($my_root.$dir);
while($file = @readdir($handle)) {
if(in_array($file, $s_skip)) { // Alles in $skip auslassen
continue;
}
elseif($count_hits>=$limit) {
break; // Maximale Trefferzahl erreicht
}
elseif(is_dir($my_root.$dir."/".$file)) { // Unterverzeichnisse durchsuchen
$s_dirs = array("$dir/$file");
search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS); // search_dir() rekursiv auf alle Unterverzeichnisse aufrufen
}
elseif(preg_match("/($s_files)$/i", $file)) { // Alle Dateien gemaess Endungen $s_files
$fd=fopen($my_root.$dir."/".$file,"r");
$text=fread($fd, $byte_size); // 50 KB
$keyword_html = htmlentities($keyword);
if($case) { // Gross-/Kleinschreibung beruecksichtigen?
$do=strstr($text, $keyword)||strstr($text, $keyword_html);
}
else {
$do=stristr($text, $keyword)||stristr($text, $keyword_html);
}
if($do) {
$count_hits++; // Treffer zaehlen
if(preg_match_all("=<title[^>]*>(.*)</title>=siU", $text, $titel)) { // Generierung des Link-Textets aus <title>...</title>
if(!$titel[1][0]) // <title></title> ist leer...
$link_title=$no_title; // ...also $no_title
else
$link_title=$titel[1][0]; // <title>...</title> vorhanden...
}
else {
$link_title=$no_title; // ...ansonsten $no_title
}
echo "<a href=\"$my_server$dir/$file\" target=\"_self\" class=\"result\">$count_hits. $link_title</a><br>"; // Ausgabe des Links
$auszug = strip_tags($text);
$keyword = preg_quote($keyword); // unescapen
$keyword = str_replace("/","\/","$keyword");
$keyword_html = preg_quote($keyword_html); // unescapen
$keyword_html = str_replace("/","\/","$keyword_html");
echo "<span class=\"extract\">";
if(preg_match_all("/((\s\S*){0,3})($keyword|$keyword_html)((\s?\S*){0,3})/i", $auszug, $match, PREG_SET_ORDER)); {
if(!$limit_extracts)
$number=count($match);
else
$number=$limit_extracts;
for ($h=0;$h<$number;$h++) { // Kein Limit angegeben also alle Vorkommen ausgeben
if (!empty($match[$h][3]))
printf("<i><b>..</b> %s<b>%s</b>%s <b>..</b></i>", $match[$h][1], $match[$h][3], $match[$h][4]);
}
}
echo "</span><br><br>";
flush();
}
fclose($fd);
}
}
@closedir($handle);
}
}
}


// search_no_hits(): Ausgabe 'keine Treffer' bei der Suche
function search_no_hits($HTTP_GET_VARS, $count_hits, $message_4) {
@$action=$HTTP_GET_VARS['action'];
if($action == "SEARCH" && $count_hits<1) // Volltextsuche, kein Treffer
echo "<p class=\"result\">$message_4</p>";
}

?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Skowhegan Savings Bank | Central Maine Bank</title>
<link href="styles/style.css" rel="stylesheet" type="text/css" />
<link href="styles/nav.css" rel="stylesheet" type="text/css" />
<link href="styles/slideshow.css" rel="stylesheet" type="text/css" />
<!--[if gt IE 6]>
<link href="styles/ieonly.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script type="text/javascript" src="scripts/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="scripts/slideshow.js"></script>
<script language="JavaScript1.2" type="text/javascript">
<!--
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;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//-->
</script>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><? include('inc_header.php');?></td>
</tr>
</table>
<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" class="table_white">
<tr>
<td><table width="850" border="0" cellpadding="0" cellspacing="0" class="table_white">
<tr>
<td width="197" valign="top"><br />
<? include('inc_onlinebanking.php');?>
<br />
<? include('inc_rates.php');?>
<br />
<? include('inc_contactus.php');?>
<br />
<? include('inc_community.php');?>
<br />
<? include('inc_enewsletter.php');?>
<br />

</td>
<td width="21">&nbsp;</td>
<td valign="top"><table width="588" border="0" align="left" cellpadding="0" cellspacing="0" class="table_white">
<tr>
<td><br /></td>
</tr>
<tr>
<td height="19" valign="middle" class="text">
<?
// search_headline(): Ueberschrift Suchergebnisse
search_headline($HTTP_GET_VARS, $message_3);
// search_error(): Auf Fehler testen und Suchfehler anzeigen
search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits);
// search_dir(): Volltextsuche in Verzeichnissen (siehe config.php4)
search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS);
// search_no_hits(): Ausgabe 'keine Treffer' bei der Suche
search_no_hits($HTTP_GET_VARS, $count_hits, $message_4);
?>
<? print_r($_POST);?></td>
</tr>
<tr>
<td valign="top" class="text"><div id="contents" align="left"></div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><? include('inc_footer.php');?></td>
</tr>
</table>

</body>
</html>

AntiHero118
04-29-2009, 08:51 PM
After much tinkering I finally got it working. Thanks again Eldarrion. :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum