Site icon Nabtron

Forward POST variables to another php page using curl

There are certain situations in which we need to forward the variables from one php page to another without resubmitting the form.

The following code simply forwards the variables submitted to the php page, once they are worked on there, to another page. For example if you need to submit the form submitted to two pages, you can submit the form to one page, and at the end of that php page, simply add the following code, and it will forward the variables to the next page.

$ch = curl_init();

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

// Optionally set a timeout
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

curl_setopt($ch, CURLOPT_URL, ‘http://site-link.com/’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, “url=index%3Dbooks&field-keywords=CURL”);
$output = curl_exec($ch);
curl_close($ch);
print $output;

Hope it helps you to forward the php post variables to the another page.

Exit mobile version