How to pass $_POST variables via PHP CURL?

Posted by w3diy - 6 months ago
$post['pcode'] = 'Pc0001254';
$post['security'] = 'DSfg874g52f5g847584jdjkf'
$post['mail'] = '[email protected]';

$url = 'http://domain_name.com/get-the-post-data.php';
$fields = array ('pcode' =>urlencode($post['pcode'],
'security' = urlencode($post['security']),
'mail' = urlencode($post['mail']));

foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');


$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
//check the result
var_dump($result);