smity911 Posted July 9, 2009 Share Posted July 9, 2009 Hi all, I found and changed the following script around a title but i am un able to get it to display file names and would be great full if any one could help me. what i want it to do is instead of looking for the file title and displaying it i am tring to get it to display the file name but it is currently pulling it from <title>HERE</title>. Oh and just wanting to know would it be possible to search the file name to? Thx in advanced. <?php /* terraserver.de/cSearch-1.0 31.07.2002 - Copyright © 2002 Holger Eichert, mailto:h.eichert@gmx.de. All rights reserved. Dieses Programm ist freie Software. Sie können es unter Berücksichtigung der GNU General Public License - Version 2 der Lizenz oder neuer, veröffentlicht durch die Free Software Foundation - weitergeben und/oder ändern. Dieses Programm wird in der Hoffnung, daß es nützlich ist, aber OHNE IRGENDEINE GARANTIE, auch ohne implizierte Garantie für MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEM BESTIMMTEN ZWECK zur Verfügung gestellt. Wenn Sie mehr wissen möchten, lesen Sie die GNU General Public License http://www.gnu.org/copyleft/gpl.html. Zusammen mit diesem Programm sollten Sie eine Kopie der GNU General Public License erhalten haben, wenn nicht schreiben Sie an Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License http://www.gnu.org/copyleft/gpl.html for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Abbout: Some people say php is not the language to do a fulltextsearch and they are right ;-) but anyway: terraserver.de/cSearch performs a realtime fulltext-search over spezified directorys including subdirectorys and returns a link and an extract of each file. Htmlspecialchars are supported so a search for "über" will return documents having "über" as well as documents having "über". Depending on the performance of your webserver, with terraserver.de/cSearch you should be able to search in about 1000 (html-)files. Systemrequirements: - Testet on Linux/Solaris/Win2000 with Apache 1.3.19 or higher and PHP4.04pl1 or higher Changes: - Added multiple Languages - German, English and French (experimental ;-) - depending on client browser's HTTP_ACCEPT_LANGUAGE with possibility to search different branches of your server - Added limitation of results per page - Added an example html-file to use the search outside php-files - Strip php- and html-tags from search except of <title></title> tags - Added advanced view on/off - Added some more features like 'match case' and the possibility to limit the number of results Configure: Edit config/config.inc.php and the language files in config/languages/ to fit your needs. Have fun... */ // Konfiguration einbinden include "config/config.inc.php"; // Aus Config-Strings Arrays machen $languages = explode(",",$languages); // get_language(): Welche Sprache einbinden? function get_language($HTTP_GET_VARS) { global $languages_path, $languages, $HTTP_GET_VARS; // Ist schon eine Sprache gewaehlt? if(isset($HTTP_GET_VARS['lan']) AND in_array($HTTP_GET_VARS['lan'], $languages)) { $l=$languages_path.$HTTP_GET_VARS['lan'].".inc.php"; } else { $client_lan=explode(",", getenv("HTTP_ACCEPT_LANGUAGE")); // Welche Sprachen akzeptiert der Browser? while(list($k,$v)=each($client_lan)) { if($l) { break; } else { reset($languages); while(list($x,$lan_file) = each($languages)) { if(substr(strtoupper($lan_file), 0, 2)==substr(strtoupper($v), 0, 2)) { $l=$languages_path.$lan_file.".inc.php"; $HTTP_GET_VARS['lan']=$lan_file; break; } } } } } // Standartsprache verwenden if(!$l) { reset($languages); $l=$languages_path.$languages[0].".inc.php"; $HTTP_GET_VARS['lan']=$languages[0]; } return $l; } // Sprachedatei einbinden include get_language($HTTP_GET_VARS); // Aus Config-Strings Arrays machen $s_dirs = explode(",",$s_dirs); $s_skip = explode(",",$s_skip); $limit_hits = explode(",",$limit_hits); $limit_perpage = explode(",",$limit_perpage); // debug(): Debugger function debugger($debug, $HTTP_GET_VARS) { global $iniset; if($debug==true) { $iniset = ini_set("error_reporting", "2047"); $output="<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">"; $output.="<tr align=\"left\" valign=\"top\" class=\"debug\"><td colspan=\"4\"><b>HTTP_GET_VARS:</b></td></tr>"; while(list($k,$v)=each($HTTP_GET_VARS)) { $output.="<tr align=\"left\" valign=\"top\" class=\"debug\"><td>KEY:</td><td><b>$k</b></td><td>VALUE:</td><td><b>$v</b></td></tr>"; } $output.="</table>"; return $output; } } // get_microtime(): Zeitstempel fuer Suchdauer function get_microtime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } // search_form(): Gibt das Suchformular aus function search_form($HTTP_GET_VARS, $advanced_view) { global $limit_hits, $limit_perpage, $default_val, $message_5, $message_6, $message_7, $message_8, $message_13, $form_action, $form_target, $short_view_case, $short_view_extracts, $max_chars; echo "<form action=\"".$form_action."\" method=\"GET\" target=\"".$form_target."\">\n", "<input type=\"hidden\" value=\"SEARCH\" name=\"action\">\n", "<input type=\"hidden\" value=\"".$HTTP_GET_VARS['lan']."\" name=\"lan\">\n", "<input type=\"text\" name=\"keyword\" class=\"text\" size=\"12\" maxlength=\"".$max_chars."\" value=\""; if(!isset($HTTP_GET_VARS['keyword'])) echo "$default_val"; else echo str_replace("&","&",htmlentities($HTTP_GET_VARS['keyword'])); if(!isset($HTTP_GET_VARS['keyword'])) echo "\" onFocus=\" if (value == '$default_val') {value=''}\" onBlur=\"if (value == '') {value='$default_val'}"; echo "\"> "; $j=count($limit_hits); if($j==1 OR $advanced_view==false) { echo "<input type=\"hidden\" value=\"".$limit_hits[0]."\" name=\"limit\">"; } else { echo "<select name=\"limit\" class=\"select\">\n"; for($i=0;$i<$j;$i++) { echo "<option value=\"".$limit_hits[$i]."\""; if(@$HTTP_GET_VARS['limit']==$limit_hits[$i]) echo "SELECTED"; echo ">$message_8 ".$limit_hits[$i]." $message_5</option>\n"; } echo "</select> "; } echo "<input type=\"submit\" value=\"OK\" class=\"button\">", "<br>\n"; if($advanced_view==true) { echo "<span class=\"checkbox\">$message_6</span> <input type=\"checkbox\" name=\"case\" value=\"true\" class=\"checkbox\""; if(@$HTTP_GET_VARS['case']) echo " CHECKED"; echo ">", " ", "<span class=\"checkbox\">$message_13:</span> <input type=\"checkbox\" name=\"extracts\" value=\"true\" class=\"checkbox\""; if(@$HTTP_GET_VARS['extracts']) echo " CHECKED"; echo ">", "<br>\n"; } else { echo "<input type=\"hidden\" value=\"".$short_view_case."\" name=\"case\">", "<input type=\"hidden\" value=\"".$short_view_extracts."\" name=\"extracts\">"; } $k=count($limit_perpage); if($k==1 OR $advanced_view==false) { echo "<input type=\"hidden\" value=\"".$limit_perpage[0]."\" name=\"perpage\">"; } else { echo "<span class=\"radio\">$message_7 "; for($i=0;$i<$k;$i++) { echo "<input type=\"radio\" name=\"perpage\" value=\"".$limit_perpage[$i]."\" class=\"radio\""; if(@$HTTP_GET_VARS['perpage']==$limit_perpage[$i] OR (!isset($HTTP_GET_VARS['perpage']) AND $i==0)) echo " CHECKED"; echo "> ", $limit_perpage[$i]." "; } echo "</span><br>"; } echo "<a href=\"http://www.terraserver.de/\" class=\"ts\" target=\"_blank\"></a>", "</form>\n"; } // search_headline(): Ueberschrift Suchergebnisse function search_headline($HTTP_GET_VARS) { global $message_3; if(@$HTTP_GET_VARS['action'] == "SEARCH") // Volltextsuche return "<p class=\"header\">$message_3 '<i>".htmlentities(stripslashes($HTTP_GET_VARS['keyword']))."</i>'</p>"; } // search_footer(): Fussbereich ausgeben function search_footer($HTTP_GET_VARS) { global $message_5, $message_9, $message_10, $message_11, $message_12, $message_14, $count_hits, $count_files, $start_time, $end_time; if(isset($HTTP_GET_VARS['action'])) { if(!isset($count_files)) $count_files=0; if(!isset($count_hits)) $count_hits=0; if(!isset($HTTP_GET_VARS['page'])) $HTTP_GET_VARS['page']=1; $start=$HTTP_GET_VARS['page']*$HTTP_GET_VARS['perpage']-$HTTP_GET_VARS['perpage']+1; if($count_hits==0) $start=0; if($HTTP_GET_VARS['perpage']*$HTTP_GET_VARS['page']<$count_hits) $end=$HTTP_GET_VARS['perpage']*$HTTP_GET_VARS['page']; else $end=$count_hits; $footer="<div class=\"menu\" align=\"center\">".go_menu($HTTP_GET_VARS, $count_hits)."</div>"; $footer.="<div class=\"footer\" align=\"center\">$message_9: <b>".$start."-".$end."</b> $message_14 <b>".$count_hits."</b>. <b>".$count_files."</b> $message_10. $message_11: <b>".number_format(($end_time-$start_time),2)."</b> $message_12"; $footer.="</div>"; flush(); return $footer; } } // go_menu(): Menu generieren function go_menu($HTTP_GET_VARS, $count_hits) { global $form_action, $form_target, $max_menu, $message_15, $message_16, $message_17, $message_18; while(list($a,$b)=each($HTTP_GET_VARS)) { // $HTTP_GET_VARS handelbarer machen $$a=$b; } if($action == "SEARCH") { // Volltextsuche // Anfang if(!$page) $page=1; // Vorige Seite $prev_page=$page-1; // Naechste Seite $next_page=$page+1; // Wieviele Seiten? if($count_hits<$limit) $total=$count_hits; else $total=$limit; if($total<=$perpage) $num_pages=1; elseif(($total%$perpage)==0) $num_pages=($total/$perpage); else $num_pages=($total/$perpage)+1; $num_pages=(int)$num_pages; // Letzte Seite $end_page=$num_pages; // Manipulierte Url if(($page>$num_pages) OR ($page<1)) { echo search_error($HTTP_GET_VARS); } // Anzeige in Abhaengigkeit von $limit/$count_hits, maximal $max_menu Eintraege $i=$page; // Default $show=$max_menu+$page; // Default if($page+$max_menu>=$num_pages+1) { $i=$num_pages-$max_menu+1; $show=$num_pages+1; } // Negative Werte korrigieren if($i<1) $i=1; // Zurueck, zum Anfang blaettern if($prev_page) { // Zurueck $prev=" <a href=\"".$form_action."?action=SEARCH&keyword=".$keyword."&limit=".$limit."&perpage=".$perpage."&page=".$prev_page."&case=".$case."&extracts=".$extracts."\" class=\"jump\" target=\"".$form_target."\" title=\"".$message_16."\">«</a> "; // Anfang $beg="<a href=\"".$form_action."?action=SEARCH&keyword=".$keyword."&limit=".$limit."&perpage=".$perpage."&page=1&case=".$case."&extracts=".$extracts."\" class=\"jump\" target=\"".$form_target."\" title=\"".$message_15."\">|«</a>"; } for($i;$i<$show;$i++) { // Link-Menu if($i*$perpage>$total) { // 'Krummes' Ende $bis=$total; } else { $bis=$i*$perpage; } if($i!=$page) { @$f=$f=($i*$perpage-$perpage+1)."-".$bis; @$menu.="<a href=\"".$form_action."?action=SEARCH&keyword=".$keyword."&limit=".$limit."&perpage=".$perpage."&page=".$i."&case=".@$case."&extracts=".@$extracts."\" class=\"menu\" target=\"".$form_target."\" title=\"".$f."\">".$f."</a> "; } elseif($total>0) { // Menu gegenwaertig ohne Link... @$menu.="<b>".($i*$perpage-$perpage+1)."-".$bis."</b> "; } } // Weiter, zum Ende blaettern if($page<$end_page) { // Weiter $next="<a href=\"".$form_action."?action=SEARCH&keyword=".$keyword."&limit=".$limit."&perpage=".$perpage."&page=".$next_page."&case=".@$case."&extracts=".@$extracts."\" class=\"jump\" target=\"".$form_target."\" title=\"".$message_17."\">»</a>"; // Ende $end=" <a href=\"".$form_action."?action=SEARCH&keyword=".$keyword."&limit=".$limit."&perpage=".$perpage."&page=".$end_page."&case=".@$case."&extracts=".@$extracts."\" class=\"jump\" target=\"".$form_target."\"title=\"".$message_18."\">»|</a> "; } } flush(); return @$beg.@$prev.@$menu.@$next.@$end; } // search_no_hits(): Ausgabe 'keine Treffer' bei der Suche function search_no_hits($HTTP_GET_VARS) { global $count_hits, $message_4; if(@$HTTP_GET_VARS['action'] == "SEARCH" AND $count_hits<1) // Volltextsuche, kein Treffer return "<p class=\"result\">$message_4</p>"; } // search_error(): Auf Fehler testen und Suchfehler anzeigen function search_error($HTTP_GET_VARS) { global $HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits, $limit_perpage, $end_time; if(isset($HTTP_GET_VARS['action']) == "SEARCH") { // Volltextsuche if(strlen(@$HTTP_GET_VARS['keyword'])<$min_chars OR strlen(@$HTTP_GET_VARS['keyword'])>$max_chars OR !in_array (@$HTTP_GET_VARS['limit'], $limit_hits) OR !in_array (@$HTTP_GET_VARS['perpage'], $limit_perpage)) { // Ist die Anfrage in Ordnung (min. '$min_chars' Zeichen, max. '$max_chars' Zeichen)? $HTTP_GET_VARS['action'] = "ERROR"; // Suche abbrechen $end_time=get_microtime(); return "<p class=\"result\"><b>$message_1</b><br>$message_2</p>"; } } } // search_dir(): Volltextsuche in Verzeichnissen function search_dir($HTTP_GET_VARS) { global $count_hits, $count_files, $my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $file_info, $end_time; while(list($a,$b)=each($HTTP_GET_VARS)) { // $HTTP_GET_VARS handelbarer machen $$a=$b; } 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($HTTP_GET_VARS); // search_dir() rekursiv auf alle Unterverzeichnisse aufrufen } elseif(preg_match("/(".str_replace(",","|",$s_files).")$/i", $file)) { // Alle Dateien gemaess Endungen $s_files $count_files++; $fd=fopen($my_root.$dir."/".$file,"r"); $text=fread($fd, $byte_size); // Default: ~50 KB $text=strip_tags($text,"<title></title>"); // Alle html-/php-tags los werden $keyword_html = htmlentities($keyword); if(@$case) { // Gross-/Kleinschreibung beruecksichtigen? $do=strstr($text, $keyword)||strstr($text, $keyword_html); $gk=""; } else { $do=stristr($text, $keyword)||stristr($text, $keyword_html); $gk="i"; } if($do) { $count_hits++; // Treffer zaehlen if(preg_match_all("=<title[^>]*>(.*)</title>=siU", $text, $titel)) { // Generierung des Link-Textes 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 } // Ausgabe der Ergebnisses pro Seite if(((@$page==1 OR !isset($page))AND $count_hits<=@$perpage) OR (@$page>1 AND $count_hits>@$page*$perpage-$perpage AND $count_hits<=@$page*$perpage)) { echo "<a href=\"$my_server$dir/$file\" target=\"_self\" class=\"result\">$count_hits. $link_title</a><br>"; // Ausgabe des Links if(@$extracts==true) { // Auszuege anzeigen? $auszug = strip_tags($text); // <title></title> entfernen $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})/".$gk."", $auszug, $match, PREG_SET_ORDER)); { if(!$limit_extracts) // Wieviele Auszuege anzeigen? $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<span class=\"match\"><b>%s</b></span>%s <b>..</b></i>", $match[$h][1], $match[$h][3], $match[$h][4]); } } echo "</span><br>"; if($file_info==true) { echo "<span class=\"file\">$my_server$dir/$file <i> - ".number_format((filesize($my_root.$dir."/".$file)/1024),0)."k - ".date("d/m/Y ",filemtime($my_root.$dir."/".$file))."</i></span><br>"; } } echo "<br>"; flush(); } } fclose($fd); } } @closedir($handle); } $end_time=get_microtime(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/165409-help-with-search-script/ Share on other sites More sharing options...
JonnoTheDev Posted July 10, 2009 Share Posted July 10, 2009 I wouldn't recommend even using this script. It is badly programmed and parts are obsolete. Obsolete $HTTP_GET_VARS The use of global variables is a major security risk and poor design. Quote Link to comment https://forums.phpfreaks.com/topic/165409-help-with-search-script/#findComment-872776 Share on other sites More sharing options...
npsari Posted July 10, 2009 Share Posted July 10, 2009 Wow, that is one huge script you showed here My prsonal opinion is to create a search script yourself I created a search script for one of my sites The reason is, because I wanted to know exactly what the script consists of Therefore, you can add and subtract in the future as much as you wish But ofcourse you can get readu scripts from the net if you dont know how to make them or dont have time Quote Link to comment https://forums.phpfreaks.com/topic/165409-help-with-search-script/#findComment-872806 Share on other sites More sharing options...
smity911 Posted July 12, 2009 Author Share Posted July 12, 2009 I wouldn't recommend even using this script. It is badly programmed and parts are obsolete. Obsolete $HTTP_GET_VARS The use of global variables is a major security risk and poor design. Thx for the advise but i was planing on using it on an intranet so security is not the bigest issue. Short of righting it my self is there and scripts that would do similar to this, as we have over 350 forms on our intranet and i need an easy way for users to ether do a mysql search or a script like the one i have shown that will enable users to type part of a file name and show a list of results that can be clicked to download, i allready have all the files in a sql db. Thx Smity Quote Link to comment https://forums.phpfreaks.com/topic/165409-help-with-search-script/#findComment-874284 Share on other sites More sharing options...
JonnoTheDev Posted July 13, 2009 Share Posted July 13, 2009 This is just simple sql. Why do you need a specific script? SELECT * FROM abc WHERE x LIKE 'myfile%' Quote Link to comment https://forums.phpfreaks.com/topic/165409-help-with-search-script/#findComment-874427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.