PHP Limit in POST variables

2019-03-06 03:19发布

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.

4条回答
Viruses.
2楼-- · 2019-03-06 03:37

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:

$encoded = base64_encode(gzcompress(serialize($original)));

$original = unserialize(gzuncompress(base64_decode($_POST['encoded'])));

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

查看更多
smile是对你的礼貌
3楼-- · 2019-03-06 03:51

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?

查看更多
劫难
4楼-- · 2019-03-06 03:55

A php.ini value ir responsible for POST max size:

post_max_size = 10M
查看更多
来,给爷笑一个
5楼-- · 2019-03-06 03:57

No need to worry about size, But I'd consider using sessions for this purpose

查看更多
登录 后发表回答