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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题