How does the post value of the html5-php pass across pages continuously (without form )?

Source: Internet
Author: User
On page A, I pass A value to page B through the POST method, for example, $ _ POST [& #039; test & #039;] & quot; learn & quot; after receiving this value on page B, I want to pass this value to Page C and use the POST method. My previous practice is to create an & amp; lt; form & amp; gt; on the B page. The elements in the form are all... on page A, I pass A value to page B through the POST method, for example
$_POST['test'] = "learn"
After receiving this value on page B, I want to pass this value to Page C and use the POST method.
My previous practice is to create The elements in the table are of the hidden type. $_POST['test']The form is then assigned, and then transmitted to the C page through the POST method.
But I think this is too troublesome. Is there any good way to pass the POST value to the C page without using a form on page B?

Reply content:

On page A, I pass A value to page B through the POST method, for example
$_POST['test'] = "learn"
After receiving this value on page B, I want to pass this value to Page C and use the POST method.
My previous practice is to createThe elements in the table are of the hidden type.$_POST['test']The form is then assigned, and then transmitted to the C page through the POST method.
But I think this is too troublesome. Is there any good way to pass the POST value to the C page without using a form on page B?

Post simulation is required to pass the post value. There are three methods for POST simulation:

  1. Curl

  2. Socket

  3. File_get_contents

The principles of these three methods are similar. They simulate HTTP access and submit POST data to the server page.

The sample code for submitting a post using curl is as follows:

$ Ch = curl_init (); // initialize curl curl_setopt ($ ch, CURLOPT_URL, $ postUrl); // specify the post URL curl_setopt ($ ch, CURLOPT_HEADER, 0 ); // set the header curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // The result is a string and the returned curl_setopt ($ ch, CURLOPT_POST, 1 ); // post submission method: curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ curlPost); $ data = curl_exec ($ ch); // run curl curl_close ($ ch );

$ CurlPost indicates the post field, which can be a string or an array. the string is like arg1 = a & arg2 = B & arg3 = c, arrays are similar to arrays ('arg1' => 'A', 'arg2' => 'B', 'arg3' => 'C.

This is very simple. You can use session to pass the value, which ensures continuous data transfer and the page can also obtain information.

1. I suggest using memcache or redis for cache storage.

Both session and cookie functions are supported.

Use session or cookie.
Of course, you can write the data to the database and retrieve it from another page.

Session, first call session_start () to enable the session.
Then, a page assigns a value to a key in the $ _ SESSION array, which can be retrieved from another page.
It is like the $ _ SESSION array can span pages.

Use localStorage. Page A saves data to localStorage, page B, and page C, which can be read only for pages in the same domain.

Use session or ajax

If you want to submit the data to page B, B jumps to Page C and C receives the post data.
When B jumps to C, the status code 307 can be used.

header("xxxx",307);

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.