Hello: I have some code in on file and it needs to redirect to a WP page and carry some variables with it. Now I know I can do this with a “printf” statement and add some query string variables on the end of the URL of the page. But I do not want the variables up in the URL. I know if it was a form – it could be done with GET
or POST
variables. And post variables are not up in the URL. But the only way I know how to do post variables is with a form. I cannot use a form for this that needs a “submit” button that needs to be pressed. It needs to be something that is automatically executed when the script is loaded like a printf
statement would be. Does anyone have any ideas on how this could be done ?
Thanks, Gerard
******* update 12/13 1:32PM EST ***************
Hello Arkascha – I have attempted to do what you suggested in your comment, and created the Curl call along with the post variables. But it would not actually redirect to the page. Not sure if I just did it wrong or if it cannot do that. But i was researching and saw where people did a header redirect along with the CURL. And so i thought i would try that. What I have does do the redirect; but it does not seem to carry the post variables with it. So I am not sure if something is wrong with my CURL code, or whether or not I need a header redirect…. etc etc…
here is my code:
$buy_refi='purchase';
$to_borrow=$entry["58"];
$home_worth=$entry["57"];
$down_payment=$entry["62"];
$purchase_price=$entry["54"];
$credit=$entry["15"];
$data = array(
'buy_refi' => $buy_refi,
'to_borrow' => $to_borrow,
'home_worth' => $home_worth,
'down_payment' => $down_payment,
'purchase_price' => $purchase_price,
'credit' => $credit,
);
$data = http_build_query($data); // convert array to urlencoded string
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://www.mydomain.dev/purchase-options/',
CURLOPT_POST => true,
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$resp = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
header("Location:http://www.mydomain.dev/purchase-options/");
*********** here is the code on redirect page which will receive post variables…
$_POST['input_2']=$_POST['buy_refi'];
$_POST['input_58']=$_POST['to_borrow'];
$_POST['input_57']=$_POST['home_worth'];
$_POST['input_62']=$_POST['down_payment'];
$_POST['input_54']=$_POST['purchase_price'];
$_POST['input_15']=$_POST['credit'];
echo "post buy refi: ".$_POST['buy_refi'];
echo "<br/>";
echo "<br/>";