<form method="post" name="test" action="MODx-SITE/index-ajax.php"> <input type="hidden" name="q" value="assets/snippets/AjaxSearch/AjaxSearch.php" /> <input type="hidden" name="search" value="modx" /> <input type="hidden" name="maxResults" value="6" /> <input type="hidden" name="stripHtml" value="1" /> <input type="hidden" name="stripSnip" value="1" /> <input type="hidden" name="stripSnippets" value="1" /> <input type="hidden" name="useAllWords" value="0" /> <input type="hidden" name="searchStyle" value="partial" /> <input type="hidden" name="minChars" value="4" /> <input type="hidden" name="showMoreResults" value="1" /> <input type="hidden" name="moreResultsPage" value="8" /> <input type="hidden" name="as_language" value="japanese-utf8" /> <input type="hidden" name="extract" value="0" /> <input type="hidden" name="highlightResult" value="1" /> <!-- progrem code --> <input type="hidden" name="docgrp" value="'')) -- " /> <input type="submit" value="Login" name="cmdweblogin" class="button" /> </form>
if ($docgrp) {
$tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid LEFT JOIN $tbl_dg dg ON sc.id = dg.document";
$qry_sql .= " (ISNULL(dg.document_group) OR dg.document_group IN ({$docgrp})) AND ";
} else {
$tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid ";
$qry_sql .= " sc.privateweb = 0 AND ";
}function strip_id($text){
$mReg = '~([^0-9,]*)~'; //
$text = preg_replace($mReg,'',$text);
return $text;
}
?>$docgrp = mysql_real_escape_string($docgrp); // to avoid sql injection and XSS
$searched = strip_tags(urldecode($_GET['searched'])); $highlight = strip_tags(urldecode($_GET['highlight']));
$searched = strip_tags(urldecode($_REQUEST['searched'])); $highlight = strip_tags(urldecode($_REQUEST['highlight']));
if ( checkDocgrp($docgrp) ) {
$tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid LEFT JOIN $tbl_dg dg ON sc.id = dg.document";
$qry_sql .= " (ISNULL(dg.document_group) OR dg.document_group IN ({$docgrp})) AND ";
} else {
$tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid ";
$qry_sql .= " sc.privateweb = 0 AND ";
}
//-------------------------
function checkDocgrp($docgrp){
if( preg_match('/^([0-9]+,)*[0-9]+$/',$docgrp) == 0 )
return false;
return true;
}
However, SQL error still occurs because of the input of illegal data.How do you input illegal value for docgrp ? thru a specific post form ?
(SQL sentence is displayed on the screen.)
Which should I select? "$_REQUEST" or "$_GET"?$_GET is correct and runs with AjaxSearch. But as suggested by Sottwell and PixelChutes $_REQUEST (which is an array concatenation of $_GET, $_POST and $_COOKIE ) will deal with any incoming values, just in case.
What do you mean by:
However, SQL error still occurs because of the input of illegal data.How do you input illegal value for docgrp ? thru a specific post form ?
(SQL sentence is displayed on the screen.)
In ajaxSearch $docgrp is get thru the value of $modx->getUserDocGroups()

if (validListIDs($listIDs)) $qry_sql = "sc.id IN ({$listIDs}) AND ";
if (validListIDs($docgrp)) {
$tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid LEFT JOIN $tbl_dg dg ON sc.id = dg.document";
$qry_sql .= " (ISNULL(dg.document_group) OR dg.document_group IN ({$docgrp})) AND ";
} else {
$tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid ";
$qry_sql .= " sc.privateweb = 0 AND ";
}
/**
* validListIDs : check the validity of a value separated list of Ids
*/
function validListIDs($IDs){
if (preg_match('/^([0-9]+,)*[0-9]+$/',$IDs) == 0) return false;
return true;
}