I've added a search function on my website where users will be able to search the content of my page.
Code:
try
{
$pdo = new PDO("mysql:host=hostname;dbname=searchdb", "searchuser", "searchpw",
array(PDO::ATTR_PERSISTENT => true));
}
catch (PDOException $ex) {
echo $ex->getMessage() . "<br>";
exit('Connection Closed');
}
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$stmt = $pdo->prepare($query);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
Now I wanted to know how to protect it from search overload. I believe anyone can create a simple bot program that can that waste my bandwidth/cpu with too many search queries.
I mean I could track the IP Address and limit it from there but I would like to avoid that route if possible.