PHP commits the use of post array parameters

Source: Internet
Author: User
This article mainly introduces the use of PHP to submit post array parameters, the interest of friends under the reference, I hope to be helpful to everyone.

The code is as follows:

$_POST[AA]


Gets the array.

The deeper question is, suppose I now need to process the parameters in the post, and then pass it on to the other server, what should I do with the parameter AA?

If you do not do any processing, after assembling the POST request, Server B gets the only array, unable to fetch the actual value.

Now the solution is: server-side A is now serialized, and then deserialized after server-side B is received. The deserialized value is then an array, and the same is obtained for the A segment.

Serialization of

Copy the Code code as follows:

$_post["AA"] =serialize ($_post[aa]);


Deserialization

$a = "a:2:{i:0;s:1:\" 1\ "; i:1;s:1:\" 2\ ";}"; Var_dump (Unserialize ($a));

What is the result:

Array (2) {[0]=> string (1) "1" [1]=> string (1) "2"}

The serialized parameters obtained in post are added with escape characters, which need to be removed before they can be deserialized successfully.

$BB = $_post["AA"]; $bb = str_replace ("\ \", "", $BB); Var_dump (Unserialize ($a));

Well, that's the result you want.

Of course, another problem is that you can simply pass the array value to a space on the page and submit it to the server. This situation also requires serialization and deserialization.

Page

<input type= "hidden" name= "AA" value= "<?php Echo Base64_encode (Serialize ($array));? > "/>var_dump (Base64_decode (unserialize (<pre class=" html "name=" code ">{1}</pre><br>post[" Post_data ']));

Summary: The above is the entire content of this article, I hope to be able to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.