【问题标题】:Check form input length via PHP with maxlength tag通过 PHP 使用 maxlength 标签检查表单输入长度
【发布时间】:2012-10-15 13:35:56
【问题描述】:

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

【问题讨论】:

  • 非常感谢您的快速回复,我同意你的看法,我也会通过 PHP 检查输入长度:)

标签: php forms input maxlength


【解决方案1】:

您应该这样做,因为任何人都可以“复制”您的表单并使用它。 服务器端检查比客户端检查好。 (很安全)

例如,您的表单:

<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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 2015-02-23
    • 2011-08-08
    • 2016-05-09
    • 2011-11-19
    • 1970-01-01
    • 2021-12-21
    相关资源
    最近更新 更多