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:
-
Curl
-
Socket
-
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);