I try to post some data to another server using curl. The problem is that I get nothing on the other server.
Server1:
$a = $USER->id;
$b = $USER->username;
error_reporting(-1);
$url = 'http://remote_server/a.php';
$data = array(
'cus' => $a,
'cust' => $b
);
$postString = http_build_query($data, '', '&');
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 2);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$post = curl_exec ($ch);
curl_close ($ch);
and on Server2:
<?php
session_start();
var_dump($_POST);
?>
Of course it doesn't work, it gives array(0) {}. So, how I will see the data on the other server?
To see the actual output of var_dump($_POST)
in Server2, you must either :
echo $post
variableServer2 side : write the content of var_dump's result in a file :
ob_start();
var_dump($_POST);
$output = ob_get_clean();
$fp = fopen('log.txt', 'a');
fwrite($fp, $output);
fclose($fp);