//Begin Environment Variables. You need to set these!//
//List of directories to be included in the search.
//Usage "path" => "url" (path to directory and URL which corresponds to directory)
//remember to include the trailing / on the URL
//Seperate Each Word into an Array Element and Compare to Keywords
$contents = explode(" ", $contents);
$j = 0;
for($j = 0; $j < count($keywords); $j++)
{
for($k = 0; $k < count($contents); $k++)
{
//compare contents with each keyword
if (!strcasecmp ($contents[$k], $keywords[$j]))
{
$match++;
break;
}
}
}
function Get_Filenames($directory)
{
//Load Directory Into Array
$handle=opendir($directory);
while ($file = readdir($handle))
{
if ($file != "." && $file != "..")
$retVal[count($retVal)] = $file;
}
//Clean up and sort
closedir($handle);
sort($retVal);
return $retVal;
}
if ( isset($keyword) )
{
$keywords = explode(" ", $keyword);
$pages = array();
while (list ($key, $val) = each ($directories))
{
$directory = $key;
chdir($directory) or die("Directory $directory Not found");
$filenames = Get_Filenames($directory);
$found = Keyword_Check($filenames,$keywords);
//add any pages with keywords in current directory to array
for($i = 0;$i < count($found); $i++)
{
$add = "$val$found[$i]";
$pages[count($pages)] = $add;
}
}
Dave Carrera wrote :591
I like the simplisity of this script BUT... is the value="$keyword" in the form area a typo as it displays $keyword in the search box on each reload...should it be name="$keyword" ???? good and cool script
Sheridan Saint-Michel wrote :592
You`re right that was an oversight =) Change
<Input Type=Text Name=keyword Value="$keyword";>
Bill Williams wrote :640
Excellent script! But there are some more minor problems:
1) If you search for a "space", then it lists all files and sub-directories of the root! Right after Get_Filenames(), Change this line:
if ( isset($keyword)) {
to:
if ( isset($keyword) && strlen($keyword) > 0) {
2) You never use the variable $numfound! I set it to 0 at the top of the script, then added this after the form:
if ($numfound > 0) {
echo "<font color=\"#0000cc\">$numfound Page(s) matching your query were found:</font>";
echo "<hr noshade size=\"1\" color=\"#dddddd\">\n";
} else {
echo "<font color=\"#cc0000\">No Pages matching your query were found. Please search again.</font>";
}
I also added:
$numfound += 1;
in the loop after the comment "//add any pages with keywords in current directory to array"
3) And finally, you include sub-directores in your results, a HUGE security hole, since I don`t want visitors to know where my admin or includes directories reside! Change this:
Sheridan Saint-Michel wrote :642
I just looked over it again and discovered that a line somehow got missed when I copied it to the site. In the script I am running I have the line
$numfound = count($pages);
Here
if ( isset($keyword) )
{
$keywords = explode(" ", $keyword);
$pages = array();
while (list ($key, $val) = each ($directories))
{
$directory = $key;
chdir($directory) or die("Directory $directory Not found");
$filenames = Get_Filenames($directory);
$found = Keyword_Check($filenames,$keywords);
//add any pages with keywords in current directory to array
for($i = 0;$i < count($found); $i++)
{
$add = "$val$found[$i]";
$pages[count($pages)] = $add;
}
}
$numfound = count($pages);
?>
Not sure how I managed to lose a line of code.... Copy and Paste has never failed me before =)
Also thanks for the comment concerning the space =)
Sheridan Saint-Michel wrote :643
I also added the line you suggested concerning the subdirectories. Thanks a lot, I appreciate it =)
mark Pau wrote :657
Very nice program...... But something want to know!
How to change the search result only ".html" and ".htm" files ?
Sheridan Saint-Michel wrote :659
Any changes to the types of files returned would be accomplished by changing the line
if ($file != "." && $file != "..")
in the Get_Filenames Function.
So to only return .htm and .html you would change that line to read something like
Heinz Ernst wrote :689
How do I manage to have the script working on a windows-system? I have Apache installed as standalone on a NT4-Machine. I appreciate helpful hints. Thanks a lot.
Heinz
john culby wrote :713
i want to search for a string such as word-word-word so i guess my question is how do i strip out a dash
thanks
Christopher Leon wrote :717
I am running this on windows2000 server, and I can get it to run if I set it to look in one directory, but when I open it up to a directory that has many subdirs, I get this message:
Warning: fopen("10.16.01","r") - Permission denied in L:\lvweb\search.php on line 24
it will also say it for the directory that I was originally searching in, and I know that it has read rights
thanks
kenneth saandvig wrote :779
I am having problems with this script... When uploading it and going to the page, it produces this output:
Parse error: parse error in /home/httpd/mywebsite/www/search.php on line 7
What a`m I doing wrong????
kenneth saandvig wrote :780
I was a little quick before... I just had to copy the "plain text". sorry =)
This is a VERY nice script
Thanx=)
java maniacs wrote :787
hmm... I get this:
Warning: fopen(".search.phtml.swp", "r") - Permission denied in /home/javamaniacs/www/dev/search.phtml on line 24
Warning: Supplied argument is not a valid File-Handle resource in /home/javamaniacs/www/dev/search.phtml on line 25
Warning: Supplied argument is not a valid File-Handle resource in /home/javamaniacs/www/dev/search.phtml on line 26
java maniacs wrote :788
D`oh! Never mind. Had the file open in vi and was trying to search a swap file! ....
Sheridan Saint-Michel wrote :789
Version 1.2 lets you filter out files from the search, so you shouldn`t run into this. I`ll post a copy here in the next few days, or you can view it at my homepage:
http://www.onlychildclub.com/Lysander/Code/
Jackson Lim wrote :799
err... can anyone explain to me how to use the codes?
I would really appreciate it.
Thank you
(just started learning, a bit confused)
gili sabach wrote :1024
Hello!
Great script, but I found that he does`nt support active search in my own language.
for example: if I`ll type word search in hebrew language he won`t find nothing, can I do something to fix this?
thank`s and again nice and really helping script.
soory about my english and have a nice day!
waiting for answer, Gili.