How does the local search work?

How can I get this log search to work in this web app?

  • I am creating a web app. The web app performs certain functions and stores results in a log file on the server. I want to add more functionality to this app. My idea was to create a search function that will search the log file for whatever text the user submits and display it on the screen without refreshing the browser. The code I have so far is below. I'm not getting any errors, but it doesn't work. Whenever I click on the search button the page just sits there as if I never clicked anything. Please help me solve this. Thank you! ----------HTML------------ Search Log:  <form id="search"> <input type="text" id="search_box" />   <input type="button" id="search_button" value="Search" / >   </form> ---------jQuery/Javascript---------- $("#search_button").click( function(){ var id = $("#search_box").val(); $("#main").load('ajax.php?logsearch&id=' + id); }); ----------PHP/ajax.php-------------- $id = $_REQUEST["id"]; //print new search box with search text still in box exec("grep " . $id . " /path/to/the/log/myLog.log", $results); //Print customized statements for 0, 1, or more results if($results.length == 0){ echo "<b>0 results returned. Please try again.</b> "; }else if($results.length == 1){ echo "<b>1 result returned.</b> "; }else{ echo "<b>" . $results.length . " results returned.</b> "; } //print results foreach($results as $line){ echo $line . " "; }

  • Answer:

    i would start by echoing the variable $id right before it is passed to the grep command. it is very important that you validate this variable because the user can enter malicious code here. have you considered using single quotes in case the user enters a search term that has a space?

Question... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.