I want to pass an array between two websites but i have difficult to do that,in my localhost i try this code :
$array = array("12" => "val", "34" => "val2");
$url = 'http://example1.com/save.php';
$post = 'data='.json_encode($array);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_exec($ch);
curl_close($ch);
then in example1.com/save.php i do this just for testing:
$result = json_decode($_POST['data'],true);
foreach ($result as $key => $value) {
echo $key.'='.$value.'<br />';
}
but this give me this warning:
Warning: Invalid argument supplied for foreach() in /home/a2549384/public_html/save.php on line 5
is there any solution?