Ga naar inhoud

[php] Zoekscript probleem (variabelen wordt niet doorgegeven


Aanbevolen berichten

Luitjes ik heb weer eens een probleem. Ik heb een pagina waarin ik een stuk opensource script (zoekmachine) heb geplakt. Ik moet het een en ander aanpassen omdat het origineel niet in de website past. Maar als ik nu een zoek optie start dan neemt hij de variabelen van de tekstbox niet mee??? Hier is de file:search.php [code:1:4ab2b36a9b] <?php global $SearchWords; /*****************************************************************************/ /* Below put all the block links in the variables. Just copy the lines down */ /* and change the link. */ /* Example: */ /* */ /* $blocktitle = "Example block"; */ /* */ /* $blocklink=array(); /* $blocklink[] = "<a href=\"link1.php\">Link 1</a>"; */ /* $blocklink[] = "<a href=\"link2.php\">Link 2</a>"; */ /* $blocklink[] = "<a href=\"link3.php\">Link 3</a>"; */ /* */ /*****************************************************************************/ $blocktitle="Quick links"; $blocklink=array(); $blocklink[]="<a href=\"link1.php\">Link 1</a>"; $blocklink[]="<a href=\"link2.php\">Link 2</a>"; $blocklink[]="<a href=\"link3.php\">Link 3</a>"; $blocklink[]="<a href=\"link4.php\">Link 4</a>"; $blocklink[]="<a href=\"link5.php\">Link 5</a>"; /*****************************************************************************/ /* Below put all the HTML content of the main-page. Note: Only use the HTML */ /* code between the <body> tags. */ /* */ /*****************************************************************************/ $maindata = ' <!-- Copy the HTML-code between this line --> <!-- and this line --> '; /*****************************************************************************/ /* Don't edit anything below this lines, page will be proccessed with the */ /* data given above. */ /*****************************************************************************/ include("includes/header.php"); ?> <tr> <td height="100%" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="159" height="100%" valign="top" background="images/blockfill_blue.gif"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="159" height="22" align="center" valign="top" background="images/blockfill_blue.gif"><font color="#FFFFFF" face="Arial"><b><?php echo $blocktitle; ?></b></font></td> </tr> <tr> <td height="10" valign="top"><img src="images/blockheader.gif" width="159" height="10"></td> </tr> <?php foreach ($blocklink as $item){ $blockcontent .= "<tr><td height=\"22\" valign=\"top\" align=\"center\" background=\"images/blockfill_grey.gif\">"; $blockcontent .= $item; $blockcontent .= "</td></tr>"; } echo $blockcontent; ?> <tr> <td height="10" valign="top"><img src="images/blockfooter.gif" width="159" height="10"></td> </tr> <tr> <td height="100%" valign="top"><img src="images/blockfill_blue.gif" width="159" height="100%"></td> </tr> <tr> <td height="12"></td> </tr> </table></td> <td width="21">&</td> <td width="100%" align="center" valign="top"><center><table width="100%" align="center" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="100%" height="100%" align="center"> <center> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="100%" height="28" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="100%" height="28">&</td> </tr> </table></td> </tr> <tr> <td height="30" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="324" height="30" align="center" valign="middle" background="images/titlebar_large_01.gif"><font color="#FFFFFF" size="4">Search this website</font> </td> <td width="100%" valign="top"><img src="images/titlebar_large_02.gif" width="100%" height="30"></td> </tr> <tr> <td height="0"></td> <td></td> </tr> <tr> <td height="1"><img src="images/spacer.gif" alt="" width="324" height="1"></td> <td></td> </tr> </table></td> </tr> <tr> <td height="338" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="100%" height="63" align="center" valign="middle"> <?php echo "<form name=\"form1\" method=\"post\" action=\"search.php?SearchWords=$Searchwords\">"; echo "<font color=\"#0000FF\" size=\"4\">Search</font><font size=\"4\">:</font>"; echo "<input type=\"text\" name=\"SearchWords\" value=\"$SearchWords\">"; echo "<input type=\"submit\" name=\"Button1\" value=\"Go\">"; echo "</form>"; ?> </td> </tr> <tr> <td height="100%"> <?php //Zoom Version 1.7.0 //A fast custom search engine //Copyright (C) Wrensoft 2000, 2001 //www.wrensoft.com //DonationWare //Use it for free, if you would like to support ongoing development //send us a donation. See our web page for details. www.wrensoft.com // //Settings // $ZoomInfo = 0; //0 = Don't display Zoom info line at bottom of search //1 = Display Zoom info line at bottom of search $OutputStyle = 1; //0 = Basic Style, Page Title, Score and URL //1 = Descriptive Stlye, Match number, Page Title, Page description, Score and URL $JoinType = 0; //0 = Search terms are combined with a boolean OR. i.e. Any words must appear on a page //1 = Search terms are combined with a boolean AND. i.e. All words must appear on a page $Logging = 1; //0 = No logging of words that a user enter. //1 = Words are logged to a file for later analysis. (See documentation for file permission issues) $LogFileName = "logs/searchwords.log"; //Path and File name of search word log file $MaxKeyWordLineLen = 2000; //Maximum line length of a single line in the KeyWords file. //Increase, if required, so that MaxKeyWordLineLen >= Number of web pages in site * 6 $WordSplit = 1; //0 = Only split input search phrase into words when a Space character is found //1 = Split input search phrase at Space ' ', UnderScore '_' , Dash '-' and Plus '+' characters // //FUNCTION: SortCompare //Compare the two values, used for sorting output results //Results that match all search terms are put first. Then results with highest score function SortCompare ($a, $b) { if ($a[2] < $b[2]) return 1; else if ($a[2] > $b[2]) return -1; else { if ($a[1] < $b[1]) return 1; else if ($a[1] > $b[1]) return -1; else return 0; } } // //MAIN FUNCTION // //Split search phrase into words if ($WordSplit == 1) $SearchWords = split ('[-_ +]', $searchword); else $SearchWords = split ('[ ]', $searchword); // Load the entire pages file into an array, all URL's on the site $urls = file ('includes/pages.dat'); // Load the entire page titles file into an array $titles = file ('includes/titles.dat'); if ($OutputStyle == 1) $descriptions = file ('includes/descriptions.dat'); //Print heading print "<h2>Search Results \"$searchword\"</h2>"; //Open keywords file $fpkeywords = fopen ("includes/keywords.dat", "r"); //Loop through all search words $numwords = count ($SearchWords); $outputline = 0; for ($sw = 0; $sw < $numwords; $sw++) { //Read in a line at a time from the keywords files while ($data = fgetcsv ($fpkeywords, $MaxKeyWordLineLen, ",")) { if (strcasecmp ($data[0], $SearchWords[$sw]) == 0) { //Keyword found, so include it in the output list $num = count ($data); for ($kw=1; $kw < $num; $kw +=2) { //Check if page is already in output list $pageexists = 0; $ipage = $data[$kw]; for ($ol = 0; $ol < $outputline; $ol++) { if ($output[$ol][0] == $ipage) { //Page is already in output list, so add to count + extra $output[$ol][1] += $data[$kw+1]; //Add in score $output[$ol][1] *= 2; //Double Score as we have two words matching $output[$ol][2] += 1; //Increase word match count $pageexists = 1; } } if ($pageexists == 0) { //New page to add to list $output[$outputline][0] = $ipage; //Page index $output[$outputline][1] = $data[$kw+1]; //Score $output[$outputline][2] = 1; //Single word match only so far $outputline++; } } break; //This search word was found, so skip to next } } //Return to start of file rewind ($fpkeywords); } //Close the files fclose ($fpkeywords); //Get number of pages matched $matches = $outputline; //Sort results in order of score, use the "SortCompare" function if ($matches > 1) usort ($output, "SortCompare"); //Count number of output lines that match ALL search terms $oline = 0; $fullmatches = 0; while (($oline < $matches) && $numwords > 1) { if ($output[$oline][2] == $numwords) $fullmatches++; $oline++; } $SomeTermMatches = $matches - $fullmatches; //Display search results if ($matches == 1) print "<i>1 Match found</i>"; else if ($matches == 0) print "<i>No Matches found</i>"; else if ($numwords > 1 && $JoinType == 0) //OR print "<i>$fullmatches pages found containing all search terms.<br>$SomeTermMatches pages found containing some search terms</i>"; else if ($numwords > 1 && $JoinType == 1) //AND print "<i>$fullmatches pages found containing all search terms.</i>"; else print "<i>$matches Matches found</i>"; //Output result $arrayline = 0; $oline = 0; while ($arrayline < $matches) { if ($JoinType == 1 && $numwords > 1 && $output[$arrayline][2] < $numwords) { $arrayline++; continue; //Boolean AND set && multiple search terms used && not all terms matched } $ipage = $output[$oline][0]; $score = $output[$oline][1]; if ($OutputStyle == 0) { //Basic style print "<p>"."Page: <a href=".$urls[$ipage].">".$titles[$ipage]."</a><br>"; print "Score: " . $score ."&&<small><i>URL:".$urls[$ipage]."</i></small></p>"; } else { //Descriptive style $PageMatch = $oline + 1; print "<p><b>".$PageMatch.".</b>&<a href=".$urls[$ipage].">".$titles[$ipage]."</a><br>"; print $descriptions[$ipage]."<br>"; print "<font color=\"#999999\"><small><i>Terms matched: ". $output[$oline][2]. " Score: " . $score ."&&URL: ".$urls[$ipage]."</i></small></font></p>"; } $oline++; $arrayline++; } //Let others know about Zoom. if ($ZoomInfo == 1) { print "<p><small><b><center>Search results generated by the <a href=\"http://www.wrensoft.com/zoom.htm\">Zoom search engine</a></center></b></small></p>"; } //Log the search words, if required if ($Logging == 1) { $LogString = Date("d-m-y H:i:s ") . $REMOTE_ADDR . " \"" .$searchword . "\"" . ", Matches = " . $matches . "\n"; $fp = fopen ($LogFileName, "a"); if ($fp != false) { fputs ($fp, $LogString); fclose ($fp); } } ?> </td> </tr> </table></td> </tr> </table> </center> </td> </tr> </table></center></td> <td width="1"></td> </tr> <tr> <td height="0"></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="1"><img src="../images/spacer.gif" alt="" width="160" height="1"></td> <td><img src="../images/spacer.gif" alt="" width="20" height="1"></td> <td></td> <td><img src="../images/spacer.gif" alt="" width="1" height="1"></td> </tr> </table></td> </tr> <?php // end of the index file include("includes/footer.php"); ?> [/code:1:4ab2b36a9b] Ik weet het is een zooitje geworden, maar ik dacht laat ik het eerst maar eens werkend krijgen en dan ruimen we het wel op. Heeft er iemand suggesties wat er fout gaat in het script? Bij voorbaat dank, Peter.
Link naar reactie
[quote:67e4c37278="R@deviL"]Maar als ik nu een zoek optie start dan neemt hij de variabelen van de tekstbox niet mee???[/quote:67e4c37278] Dan is de eerste stap om te kijken of dit inderdaad zo is. Schrijf dus alle noodzakelijke gegevens van het het verwerkende script eens weg als debug informatie. En ga daarna kijken in de flow van je programma hoe het script reageert adhv deze gegevens of hoe deze zou moeten reageren. M.a.w. dit is standaard debug werk.
Link naar reactie
Je kan bijvoorbeeld alle binnengekomen variabelen bekijken met [code:1:e5ea086f51] <?php echo "<p>Alle POST vars:<br />"; foreach ($_POST as $key => $value) { echo $key, " = ", $value, "<br />"; } echo "</p>"; echo "<p>Alle GET vars:<br />"; foreach ($_GET as $key => $value) { echo $key, " = ", $value, "<br />"; } echo "</p>"; ?> [/code:1:e5ea086f51] Bovenstaande is ff zonder testen, dus er kunnen foutjes in zitten. Bovendien is bovenstaande een beetje afhankelijk van de PHP versie die je hebt (meer info hierover kan je vinden in de [url=http://www.php.net/manual/nl/language.variables.external.php]PHP manual[/url])
Link naar reactie

Om een reactie te plaatsen, moet je eerst inloggen

Gast
Reageer op dit topic

×   Geplakt als verrijkte tekst.   Herstel opmaak

  Er zijn maximaal 75 emoji toegestaan.

×   Je link werd automatisch ingevoegd.   Tonen als normale link

×   Je vorige inhoud werd hersteld.   Leeg de tekstverwerker

×   Je kunt afbeeldingen niet direct plakken. Upload of voeg afbeeldingen vanaf een URL in

×
×
  • Nieuwe aanmaken...