I passed a value through the Post method on a page through the table one-way b page, for example
$_POST['test'] = "learn"
b page after receiving this value, I want to pass this value to the C page, the same post method.
My previous practice was to do a B page , the elements inside are all hidden types, and the one you get from page a
$_POST['test']The form is then assigned to the C page via the Post method.
But think this is too troublesome, there is no good way, you can not use the form on page B, the value of post to the C page?
Reply content:
I passed a value through the Post method on a page through the table one-way b page, for example
$_POST['test'] = "learn"
b page after receiving this value, I want to pass this value to the C page, the same post method.
My previous practice is to do on the B page, the elements are the hidden type, the page from a to be $_POST['test'] assigned to the form, and then passed through the Post method to the C page.
But think this is too troublesome, there is no good way, you can not use the form on page B, the value of post to the C page?
Post simulation is required to pass the post value, and there are three ways to post the simulation:
Curl
Socket
File_get_contents
These three methods are similar in principle, which simulates HTTP access and submits the post data to the server page.
Curl carries out the post-commit sample code as follows:
$ch = curl_init(); //初始化curl curl_setopt($ch, CURLOPT_URL,$postUrl);//指定post网页地址 curl_setopt($ch, CURLOPT_HEADER, 0);//设置header curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且返回输出 curl_setopt($ch, CURLOPT_POST, 1);//post提交方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); $data = curl_exec($ch);//运行curl curl_close($ch);
Where $curlpost is a post field, which can be a string or an array, and the string is arg1=a&arg2=b&arg3=c so that the array resembles array (' arg1 ' = ' a ', ' arg2 ' = ' B ', ' Arg3 ' = ' C ') this way.
This is very simple, you can use the session to pass the value, so that the data can be continuously transmitted, and the page can also get information
1. I recommend using Memcache or Redis cache storage
Session,cookie can All
Use a session or cookie.
Of course you can write the data to the database and take it out on another page.
Session, first call Session_Start () to open the session.
A page then assigns a key to the $_session array, which can be taken out on another page.
It's like $_session This array can span pages.
Use Localstorage. A page to save the data to Localstorage, b page, C page, as long as the page under the same domain can be read.
Use the session or use Ajax
If you are doing a jump and want to submit to page B, B jumps to C, then C can receive the post data
Then B jump to C can use 307 status code to jump
header("xxxx",307);