我的问题很简单:如果我在 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
}
https://stackoverflow.com/questions/12896766/