php - 使用 maxlength 标签通过 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
}

https://stackoverflow.com/questions/12896766/

相关文章:

sql - SQL Server 中的窗口函数

c# - 从字符串中删除无法识别的 ASCII 字符

css - 带 float 的无序列表项 :left do not float properly

asp.net - 如何在 vb.net 中做正则表达式

vb.net - VB字典包含值返回键

ruby-on-rails - 是否可以在 Rails 中更改 URL 中的 Controller

php - 将 PDF 存储在 MySQL 数据库中

security - 20字节数据CRC16冲突的可能性有多大?

php - 如何使用 SimpleXML 解析忽略错误的 XML

ruby-on-rails - 在 Rails 3 的邮件拦截器中设置 header