易于在PHP中实现
您可以在您的Web服务器中执行此速率限制,这在这里是离题的,但如果配置正确,Apache、Nginx等都可以执行此操作易于在PHP中实现,php,mysql,ajax,security,Php,Mysql,Ajax,Security,您可以在您的Web服务器中执行此速率限制,这在这里是离题的,但如果配置正确,Apache、Nginx等都可以执行此操作 您可以实现验证码之类的功能,这样有效的查询只能由人工发送 您可以为这些函数实现身份验证,并接受通过身份验证的用户利用DoS的剩余风险。你可以用不同的方法处理,例如服务条款 限速可以在应用程序端或web服务器端进行,我建议在web服务器端进行:,iI从上一篇文章中,我认为验证码可能是最好的方式,因为我没有完全访问web服务器的权限,因为我正在使用GoDaddy共享服务器来完成我的
限速可以在应用程序端或web服务器端进行,我建议在web服务器端进行:,iI从上一篇文章中,我认为验证码可能是最好的方式,因为我没有完全访问web服务器的权限,因为我正在使用GoDaddy共享服务器来完成我的这个小个人项目。我想我了解SQL注入和htmlspecialchars。我将其更改为$q=filter\u var($\u GET['q'],filter\u SANITIZE\u STRING);但我不认为这可以防止您上面概述的示例,但我对MySQL的了解还不足以确定。你能给我一个例子,我的代码中有准备好的语句、PHP PDO或ORM,因为我没有很好地理解。数据库中的名字和姓氏在使用FILTER_SANITIZE_STRING之前都经过了清理,但我确实添加了htmlspecialchars($row['firstname'])。" " . htmlspecialchars($row['lastname'])根据您的建议,以防万一。该id将成为将来指向新页面的链接,我只是还没有创建该页面。所以它将是
<script>
function finduser(str) {
if (str == "") {
document.getElementById("txtstatus").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtstatus").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","search.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$q = htmlspecialchars($_GET['q']);
$con = mysqli_connect('localhost','user','pass','db');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"db");
$sql="SELECT * FROM people WHERE CONCAT( firstname, ' ', lastname) LIKE '".$q."' OR phone LIKE '".$q."' OR email LIKE '".$q."'";
$result = mysqli_query($con,$sql);
$num_rows = mysqli_num_rows($result);
echo "<div class='records'><small>" . $num_rows . " records</small></div>";
while($row = mysqli_fetch_array($result)) {
if (is_null($row['hidden'])) {
} else {
continue;
}
echo "<div class='people'><small><a href='" . $row['id'] . "'>" . $row['firstname'] . " " . $row['lastname'] . "</a> submitted on " . date("M j\, Y", strtotime($row['timestamp']))"</small></div>";
}
echo "</ul>";
mysqli_close($con);
?>
</body>
</html>
SELECT * FROM people WHERE CONCAT( firstname, ' ', lastname) LIKE ' union select * from other; -- \' OR phone LIKE ' union select * from other; -- \' OR email LIKE ' union select * from other; -- \'
SELECT * FROM people WHERE CONCAT( firstname, ' ', lastname) LIKE '...' union select * from other