Hi,
My requirement is to initiate a HTTP post request using php code.
There are two ways I know, both having their limitations -
1. Doing
header("Location:./redirected.php");
It will redirect the browser to redirected.php, but there is no way I can specify POST variables.
2. Using cURL
$redirect_handler = curl_init();
curl_setopt($redirect_handler, CURLOPT_URL, SITE_ROOT."redirected.php");
curl_setopt($redirect_handler, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($redirect_handler, CURLOPT_TIMEOUT, 60);
curl_setopt($redirect_handler, CURLOPT_POST, 1);
curl_setopt($redirect_handler, CURLOPT_POSTFIELDS, $post_fields_array);
curl_exec($redirect_handler);
if (curl_errno($redirect_handler)) {
print "Error: " . curl_error($redirect_handler);
}
curl_close($redirect_handler);
This one is pretty good as I can redirect the browser to redirected.php with some POST data. But, this will create a new session and I loose data set in the session.
Is there any way using which I can preserve both POST & SESSION variables data ?