you could add some kind of validation to the forms
here is one suggestion but not the greatest since the patterns could change.
then run this code on the search term before acting on the search and if it passes then execute the search.
Code: Select all
function validateSearchInput($input) {
// Convert to lowercase to detect common SQL keywords regardless of case
$inputLower = strtolower($input);
// Pattern to detect SQL keywords and suspicious characters
$pattern = '/(\b(select|union|from|all|where|insert|delete|update|null|count|table|or|and|into|create|drop)\b|--|;|\'|")/i';
// Check if the input matches the pattern
if (preg_match($pattern, $inputLower)) {
// Reject the input if suspicious patterns are detected
return false;
}
// Sanitize the input if needed or just return it if clean
return htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
}
Another possible way would be search terms length so its less then x since most people don't type in a book to search for something.