我想阻止搜索框中的某些搜索....地址如下所示:
http://domain.com/search.php?search=dog
如何设置数组或阻止搜索词“dog”的内容?
<form id="headbar-search" action="search.php" method="GET" x-webkit-speech="x-webkit-speech">
<input type="text" name="search" id="jsid-search-input" value="<?php echo$_GET['search']; ?>" class="ui-autocomplete-input search search_input" placeholder="Search…" tabindex="1"/>
<div class="ui-widget"></div>
</form>
的search.php
<?php include 'header.php'; ?>
<!-- Container -->
<div id="container">
<div class="left">
<div class="pic" style="overflow:hidden; margin-top:5px;">
<div style="margin:0 0 5px 0;overflow:hidden;border:none;height:auto;">
<div class="video-container" style="text-align: left; background: #fff;">
<h2>Search results for: <?php echo htmlspecialchars($_GET['search'], ENT_QUOTES, 'UTF-8'); ?></h2>
________________________________________________________________________________________
<br><br>
<?php
if($svid) {
$squerys = mysql_query("SELECT * FROM videos WHERE title LIKE '%$word%' OR author LIKE '%$word%'");
while($ft = mysql_fetch_array($squerys)){
?>
<table>
<tr>
<td>
<?php if($st['seo'] == 1) { ?>
<a href="./<?php echo seo($ft['title'], $ft['id']); ?>.html">
<?php }else{ ?>
<a href="./?v=<?php echo$ft['id'];?>">
<?php } ?>
<div class="image-container"><img src="<?php echo$ft['thumb_large']; ?>" width="120" height="130"></div></a></td>
<td style="padding-left:10px; vertical-align:top;"><h3>
<?php if($st['seo'] == 1) { ?>
<a href="./<?php echo seo($ft['title'], $ft['id']); ?>.html">
<?php }else{ ?>
<a href="./?v=<?php echo$ft['id'];?>">
<?php } ?>
<?php echo stripslashes($ft['title']); ?></a></h3>By: <?php echo$ft['author']; ?><br><?php echo number_format(round($ft['views'])); ?> views</td>
</tr>
<br>
</table>
<?php
}
}else{
echo"No results found.";
}
?>
</div>
<div style="margin: 5px 0 0 0;"></div>
</div></div>
</div>
<?php include 'sidebar.php'; ?>
<div class="clear"></div>
</div>
<!-- Container -->
<?php include 'footer.php'; ?>
答案 0 :(得分:1)
非常快速的标记
$Naughty_Words = array ("Cat","dog");
function DetermineBanned ($Input,$Array){
if (in_array($Input,$Array)){
return true;
}
return false;
}
var_dump(DetermineBanned("Cat",$Naughty_Words)); // Returns bool(true)
var_dump(DetermineBanned("dd",$Naughty_Words)); // Returns bool(false)
var_dump(DetermineBanned("CatMan",$Naughty_Words)); // Returns bool(false)
var_dump(DetermineBanned("CatMan",$Naughty_Words)); // bool(false)
var_dump(DetermineBanned("CatDog",$Naughty_Words)); // bool(false)
/// Due to the lack of initial code being shown in your question, I have spotted a bug, it's up to you to decide how to make it fool proof
//Validate with
if (DetermineBanned($_GET['Key'],$Naughty_Words) !== false){
echo "Banned Words Detected";
exit;
}
答案 1 :(得分:1)
必须在search.php文件中完成。
示例:
$excluded_words = array("dog", "hello", "world");
if(in_array($_GET['search'], $excluded_words) {
echo "Keyword not found";
}
注意:这只是你传递一个单词
答案 2 :(得分:1)
在你的html和php之间添加一些javascript。
<form>
<input type="text" id="search-box" value="" placeholder="Search…"/>
<input type="submit" onclick="search()"/>
</form>
javascript
var badWords = ["dog"];
function search() {
var searchStr = document.getElementById("search-box").value;
var badWordHit = false;
for (key in badWords) {
if (badWords[key] == searchStr) {
badWordHit = true;
}
}
if (badWordHit) {
alert("I ain't searchin' for no dog");
} else {
alert("searching");
// do ajax request here
}
}