【问题标题】:Using PHP to Limit the length of text that can be sent to server使用 PHP 限制可以发送到服务器的文本长度
【发布时间】:2011-08-16 11:32:34
【问题描述】:

我知道如何在使用 HTML 的用户表单上执行此操作。但是,恶意用户可以绕过该表单来调用服务器操作页面并发送异常大的文本。

无论如何要拒绝来自服务器的此类请求。或许,有一种机制可以让我们在实际到达之前提前知道到达的 POST 数据的大小,类似于上传大文件。

【问题讨论】:

    标签: php textbox text-size large-data


    【解决方案1】:

    您可以使用Suhosin。 这是一个PHP的保护系统。在设置中,您可以禁止超过一定长度的请求。

    【讨论】:

    • 感谢您发布链接。该项目将有助于解决这个问题和其他安全要求。
    【解决方案2】:

    编辑php.ini 文件并将最大帖子大小设置为您希望允许的兆字节数。请记住,对于长篇博文,您需要它足够高。

    post_max_size = 4M
    

    您应该检查的其他设置是

    ; Maximum execution time of each script, in seconds
    ; http://php.net/max-execution-time
    ; Note: This directive is hardcoded to 0 for the CLI SAPI
    max_execution_time = 30
    
    ; Maximum amount of time each script may spend parsing request data. It's a good
    ; idea to limit this time on productions servers in order to eliminate unexpectedly
    ; long running scripts.
    ; Note: This directive is hardcoded to -1 for the CLI SAPI
    ; Default Value: -1 (Unlimited)
    ; Development Value: 60 (60 seconds)
    ; Production Value: 60 (60 seconds)
    ; http://php.net/max-input-time
    max_input_time = 60
    
    ; Maximum amount of memory a script may consume (128MB)
    ; http://php.net/memory-limit
    memory_limit = 30MB
    

    如果您使用的是 Apache 或 Nginx,您还可以在服务器配置中设置最大请求大小,以便他们可以在请求之前阻止请求,甚至 到达 php。

    【讨论】:

    • 哦,是的,PHP.ini 文件。它必须有这样的信息:)。需要注意的是,服务器实际上会在开始接收大量文本之前拒绝请求,对吧?
    【解决方案3】:

    当 PHP 处理 POST 数据时,已经有点晚了。这最好在 Web 服务器级别完成。如果您使用的是 Apache,请查看 LimitRequestBody 指令。

    【讨论】:

      猜你喜欢
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      • 2017-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多