Php submits post array parameter instance Analysis _ PHP

Source: Internet
Author: User
This article mainly introduces the usage of php to submit the post array parameters, and analyzes the related skills of php to submit parameters using post in combination with examples, for more information about how to use php to submit post array parameters, see the example in this article. We will share this with you for your reference. The details are as follows:

First, to transfer an array from a page to server a in php, multiple spaces on the page must have the same name, and the name must be "aa []", note that you need to add an array symbol so that it can be obtained on server.

The code is as follows:

$ _ POST [aa]


The result is an array.

A deeper problem is that, if I need to process the parameters in post and then send them to another server, how should I pass the aa parameter?

If no processing is done, after the post request is assembled, server B will always get the Array and cannot get the actual value.

The solution is: now server a is serialized and then deserialized after server B receives the request. In this way, the deserialization value is an array, which is the same as that obtained in Section.

The code is 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 deserialization is successful.

$bb = $_POST["aa"];$bb = str_replace("\\", '', $bb);var_dump(unserialize($a));

Well, this is the result you want.

Of course, another problem is that you can directly pass the array value to a space on the page and submit it to the server. In this case, serialization and deserialization are also required.

Page

var_dump(base64_decode(unserialize(
{1}

POST['post_data'])));

I don't know what the function of adding this base64_encode seems to be for Chinese encoding?

I hope this article will help you with 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.