PHP submit Post Array parameter example analysis

Source: Internet
Author: User
Tags php programming
This paper analyzes the use of PHP to submit post array parameters. Share to everyone for your reference, as follows:

First of all, PHP in order to transfer from the page array to server A, multiple spaces on the page with the same name, and for the name is required, that is Name= "aa[]", notice here to add an array of symbols, so that the server can be taken to a

Copy the Code code 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

Var_dump (Base64_decode (Unserialize (
{1}

post[' Post_data ')));

I do not know what the effect of adding this base64_encode, seems to be to the Chinese code it?

I hope this article is helpful to you in PHP programming.

The above describes the PHP submit post array parameter analysis, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.