使用PHP限制可以发送到服务器的文本的长度

|| 我知道如何使用HTML在用户表单上执行此操作。但是,恶意用户可以通过该表格来调用服务器操作页面并发送异常大的文本。 无论如何,有否拒绝来自服务器的此类请求。也许,有一种机制可以使我们提前了解实际到达的POST数据的大小,类似于上传大型文件。     
已邀请:
编辑“ 0”文件,并将最大帖子大小设置为您要允许的兆字节数。请记住,对于长篇博客文章,您需要足够高的内容,而对于其他内容则不需要。
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之前将其阻止。     
您可以使用Suhosin。 它是PHP的保护系统。在这些设置中,您可以禁止超过一定长度的请求。     
在PHP处理POST数据时,已经有点晚了。这可以在Web服务器级别更好地完成。如果您使用的是Apache,请查看LimitRequestBody指令。     

要回复问题请先登录注册