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

发布于 2024-11-04 13:14:01 字数 144 浏览 6 评论 0原文

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

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

I know how to do this on a user form using HTML. However, malicious users can by pass that form to call the server action page and send abnormally large sized text.

Is there anyway to deny such requests from the server. Perhaps, there is a mechanism by which we can realize in advance the size of POST data that is arriving before it actually arrives, similar to upload of huge files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

茶色山野 2024-11-11 13:14:01

编辑 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 之前阻止请求。

Edit the php.ini file and set the max post size to the number in megabytes you want to allow. Keep in mind you need it high enough for long blog posts and what not.

post_max_size = 4M

Other settings you should check are

; 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

If you are using Apache or Nginx you can also set the max request size in the server config so they can block the request before it even reaches php.

匿名。 2024-11-11 13:14:01

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

You can use Suhosin.
It's a protection system for PHP. And among the settings, you can forbid requests over a certain length.

月牙弯弯 2024-11-11 13:14:01

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

By the time PHP processes the POST data, it's a little late. This is better accomplished at the web server level. If you're using Apache, check out the LimitRequestBody directive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文