PHP submit Post Array parameter example analysis _php tips

Source: Internet
Author: User
Tags php programming

This article analyzes the usage of the PHP submit post array parameters. Share to everyone for your reference, specific as follows:

First in PHP to send the array from the page to server A, to the same name in multiple spaces on the page, and for the names are required, that is Name= "aa[]", note here to add an array of symbols, so as to be in service-side A to fetch

Copy Code code as follows:
$_POST[AA]

The resulting array.

The deeper question is, suppose I now need to deal with the parameters in post, and then send it to another server, how do I pass the parameter AA?

If no processing is done, after the post request is assembled, Server B will always get an array and cannot fetch the actual value.

The solution now is to serialize the service-side A and then deserialize it after Server B receives it. So the deserialized value is an array, and the same as paragraph a gets.

Serialization of

Copy 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 parameter obtained in post has been added with the escape character, which needs to be removed before it 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 pass the array value directly to a space of the page, submitted to the server. This situation also needs to be serialized and deserialized.

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 ']));

Do not know add this base64_encode have what effect, appear to be to encode Chinese?

I hope this article will help you with your PHP programming.

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.