Hi. The below script is functioning, but I cant get the results to be a link to thier correct path.
The first result printed has the href, but the path created starts with "http://www.mysite.com/", after which is the path that I want for the href. The second line of results shows the correct path but I can't seem to make that path the actual URL created (even if I put the href tags around it, it still prints out as starting with "http://www.mysite.com/"... just like the first results). This script lives in the folder that is mysite.com, so it seems like a security thing, putting the path in front of the results no matter what I do.
Sorry for the length, but I wanted to make sure I left nothing out. Thanks.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {font-family:arial, helvetica; font-style:normal}
p {font-size:10pt; font-weight:normal; color:#004}
td {font-size:9pt; font-weight:normal; color:#005; padding:8}
h1 {font-size:14pt; font-weight:bold; color:#400}
h3 {font-size:10pt; font-weight:bold; color:#006}
table {border-style:solid; border-color:#000000; border-width:1px}
#search {font-size:9pt; font-weight:normal; color:#030; background:#FFFFFB}
#search a {font-size:9pt; font-weight:normal}
#search th {font-size:10pt; font-weight:bold; color:#FFF; background:#006db2; padding:2}
#copyright {font-size:7pt; color:#006}
-->
</style>
</head>
<body bgcolor="#FFFFFF">
<?
if (isset($_REQUEST['search_term'])) $search_term = $_REQUEST['search_term'];
function search_dir () {
global $cur_path, $dir_depth, $matches;
if ($matches > 100) return;
$s_dir='';
for ($c=0; $c<=$dir_depth; $c++) $s_dir .= $cur_path[$c];
$dhandle=opendir($s_dir);
while ($file = readdir($dhandle)) {
if (($file!='.') && ($file!='..')) {
if (is_readable($s_dir.$file)) {
if (is_file($s_dir.$file)) {
$file_ext = substr($file, strlen($file)-3, 3);
if ($file_ext == 'tml') search_file($s_dir.$file);
//if ($file_ext == 'php' || $file_ext=='tml')
}
elseif (is_dir($s_dir.$file)) {
if ($file=='sitework' || $file=='WEBALIZER_REPORTS' || $file=='service' || $file=='rreal' || $file=='poppy' || $file=='phptest') continue;
$cur_path[++$dir_depth] = ($file."/");
search_dir();
$dir_depth--;
}
}
}
}
}
function search_file ($file) {
global $cur_path, $dir_depth, $search_term, $results, $r_text, $r_title, $matches;
$s_dir="";
for ($c=0; $c<=$dir_depth; $c++) $s_dir .= $cur_path[$c];
$f_size = filesize($file);
if ($f_size>100000) $f_size=100000;
$f_handle = fopen($file, "r");
@ $f_data = fread($f_handle, $f_size);
if (strpos($f_data, 'SSIGNORE')!==FALSE) return;
$f_dlc = strtolower($f_data);
$t_text = "";
$in_tag = 0;
if ($text = strstr(($f_dlc), $search_term)) {
$results[$matches] = $file;
$text = substr($text, 0, 500);
@ $text = str_replace ($search_term, "<font color=\"#FF0000\"><b>".$search_term. "</b></font>");
$r_text [$matches] = "...". $text. "...";
$t_start = strpos ($f_dlc, "<title>") + 7;
$t_end = strpos ($f_dlc, "</title>");
$r_title[$matches++] = substr($f_data, $t_start, $t_end-$t_start);
}
fclose($f_handle);
}
?>
<center><br>
<p>
<table border="0">
<tr valign="top">
<td>
<!--<form action="<? echo $PHP_SELF; ?>" method="post">-->
<form action="http://www.mysite.com/search.php" method="post">
<input type="text" name="search_term" size="40" maxlength="40" value="<? echo $search_term ?>">
<input type="submit" value="Search">
</form>
</td></tr></table><br>
<table cellpadding=8 bgcolor="#FFFFEE">
<?
$dir_depth=0;
$cur_path = array("./");
$results = array("");
$r_text = array("");
$r_title = array("");
$matches=0;
$search_term=strtolower($search_term);
if (strcmp($search_term, "")!=0) { search_dir(); }
echo "<table id=\"search\" cellpadding=8 bgcolor=\"#FFFFEE\"><tr><td align=\"center\" colspan=2>";
echo "<h4>Search Results For $search_term</h4>$matches pages found</td></tr>";
$c="#FFFFF8";
$results = str_replace("folder1","site1.com",$results);
$results = str_replace("folder2","site2.com",$results);
$results = str_replace("folder3","site3.com",$results);
$results = str_replace("./","",$results);
$results = str_replace("main_folder/","",$results);
for ($a=0; $a<$matches; $a++) {
if ($c=="#FFFFF8") {$c="#F8F8F8";} else {$c="#FFFFF8";}
echo "<tr><td align=\"left\" bgcolor=\"$c\">";
echo "<a href=\"$results[$a]\" title=\"Go To This Page\">$r_title[$a]</a>";
echo "<br> $results[$a]";
echo "</td></tr>";
}
echo "</table>";
?>
<br>
</center>
</body>
</html>