I have a page a.php
that uses cURL to post data to b.php
page.
However, when the page header to b.php
, I didn't receive any POST data.
Here is my code:
$data=array();
$data['firstname']='A';
$data['lastname']='B';
$post_str='';
foreach($data as $key=>$value){
$post_str.=$key.'='.urlencode($value).'&';
}
$post_str=substr($post_str, 0, -1);//Remove last & from loop
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/b.php');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response=curl_exec($ch);
curl_close($ch);
header('location:b.php');
b.php page
echo $_POST['firstname'];