PHP POST 变量的限制
我正在尝试通过 POST 方法将数组发送到 PHP 脚本。首先我serialize()它,然后使用base64_encode()它。接收到它后,脚本会base64_decode()它,然后unserialize()它。我知道使用 base64_encode 函数会使数据大小增加 33%,所以我担心 POST 变量可能会被淹没,从而给我一个错误。可 POST 的字符串是否有限制?或者更好的是,除了 base64_encode 之外,还有其他方法可以将数组正确传递给其他脚本吗?顺便说一句,如果在序列化时不使用 base64_ 函数,我会收到“错误:..偏移”通知。
I'm trying to send an array to a PHP script via POST method. First I serialize() it, then used base64_encode() on it. After receving it, the script then base64_decode() it then unserialize() it. I know that using base64_encode functions increases the data size by 33%, so I'm worried that the POST variables might be overwhelmed, and thus giving me an error. Is there a limit to a string that can be POST'ed? Or better, is there another way that I can use other than base64_encode to correctly pass the array to the other script? By the way, without using base64_ functions on serialization, I get the "Error:.. offset" notice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
php.ini 值负责 POST 最大大小:
A php.ini value ir responsible for POST max size:
这取决于数组的内容。如果主要是文本,那么您可以使用 gzcompress/gzuncompress 压缩/解压缩生成的序列化对象:
gzencode/gzdecode 可能会为较大尺寸的数据提供更好的压缩。如果你的数组包含二进制数据,或者更糟糕的压缩数据,那么这种技术可能不会有太大好处。
除了已经提到的 PHP 配置之外,您的 Web 服务器还可以施加 POST 大小限制,例如 apache 中的 LimitRequestBody 指令: http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody
It would depend on the contents of the array. If it is mostly text, then you could compress/decompress using gzcompress/gzuncompress the resulting serialized object:
gzencode/gzdecode will probably give better compression for larger size data. If your aray contains binary data, or even worse compressed data, then this technique will probably not gain much if anything.
In addition to the PHP configuration already mentioned, your web server can also impose POST size limits, for instance the LimitRequestBody directive in apache: http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody
无需担心大小,但我会考虑使用 sessions 来实现此目的
No need to worry about size, But I'd consider using sessions for this purpose
1) 可以 POST 的最大数据量是 php.ini 中的 post_max_size 指令。请参阅: http://www.php.net /manual/en/ini.core.php#ini.post-max-size
2)也许你可以通过$_SESSION来做到这一点?
1) The maximum amount of data you can POST is post_max_size directive in php.ini. See: http://www.php.net/manual/en/ini.core.php#ini.post-max-size
2) Perhaps you can do it through $_SESSION?