Redirect GET data from a page using POST to another page
Hi I have a php srcript that receives GET data and I want to redirect the data from GET to开发者_JS百科 another page in wordpress using POST. It's that possible, and how?
Thank's for the help.
The only way this could be done in pure PHP is by using cURL and printing the result of that request in the page:
<?php
// sort post data
$postarray = array();
foreach ($_GET as $getvar => $getval){
$postarray[] = $getvar.'='.urlencode($getval);
}
$poststring = implode('&',$postarray);
// fetch url
$curl = curl_init("http://www.yourdomain.com/yourpage.php");
curl_setopt($ch,CURLOPT_POST,count($postarray));
curl_setopt($ch,CURLOPT_POSTFIELDS,$poststring);
$data = curl_exec($curl);
curl_close($curl);
// print data
print $data;
?>
Obviously you'd validate the GET data before you post it. If there's another way you can do this I'd be interested to know as this method is not ideal. Firstly, cURL must be enabled in PHP, and secondly there will be some overhead in requesting another URL.
Only using form and javascript, which is not bulletproof.
精彩评论