duanbiyi7319 2014-04-02 03:21 采纳率: 100%
浏览 23
已采纳

我想将文本的最大用户输入设置为600字节。 PHP

I had no option but to ask you pros to help me out.

Well,I have a HTML form that allows the user input a message and a name.I wanted to set the message's maximum byte to 600-byte and set the name's max byte to 30 byte, but should I use the php to set the limit of user input? If there is a way to handle it in php I would want to know .

<form id="formed"  action="second.php" method="post">
        <textarea rows="5" cols="20" name="text" id="text"></textarea><br />
        <input type="text" name="name" id="name"/><br />
        <input type="submit" name="sub" id="sub"/><input type="button" id="display" value="display">
    </form>
  • 写回答

2条回答 默认 最新

  • drgc9632 2014-04-02 03:35
    关注

    You should detect this on both the client and server side. Doing it on the client side lets the user know they shouldn't make the string any longer, and doing it on the server side ensures that the string actually won't be any longer than what you want.

    The html on the client side can be modified by anyone through a tool such as the developer tools in a browser, so one could remove the maxlength property of your html elements and then send a string much longer than 30 characters.

    <textarea rows="5" cols="20" name="text" id="text" maxlength="600"></textarea>
    <input type="text" name="name" id="name" maxlength="30">
    
    if(strlen($_POST['name']) > 30) {
       // Name is too long, report an error to the user
    }
    
    if(strlen($_POST['text']) > 600) {
       // Text is too long, report an error to the user
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答