通过带有最大长度标签的 PHP 检查表单输入长度



我的问题很简单:如果我在HTML表单中有一些带有maxlength标签的输入字段,我也必须通过PHP检查输入长度?

你应该,因为任何人都可以"复制"你的表单并使用它。服务器端检查优于客户端检查。(很安全)

例如,您的表单:

<form method='post' action='/pay.php'>
<input type='text' maxlength='10' name='addres'>
</form>

我可以轻松地做这样的事情:(并将其上传到一些免费服务器或类似的东西)

<form method='post' action='http://www.yourdomain.com/pay.php'>
<input type='text' name='addres'><!--no maxlength='10' for me-->
</form>

现在我有点"超越"你的限制。

但是,您可以编辑pay.php文件:

$addres = clean_input($_POST['addres']); //A custom function to make sure it's a clean string
if(strlen($addres) > 100)
{
  //Something weird
}
else
{
  //We're good
}

最新更新