use php to parse json data posted from another php file
- by akshay.is.gr8
my web hosting has blocked the outward traffic so i am using a free web hosting to read data and post it to my server but the problem is that my php file receives data in the $_REQUEST variable but is not able to parse it.
post.php
function postCon($pCon){
//echo $pCon;
$ch = curl_init('http://localhost/rss/recv.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "data=$pCon");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$d=curl_exec ($ch);
echo $d."<br />";
curl_close ($ch);
}
recv.php
<?php
if(!json_decode($_REQUEST['data']))
echo "json error";
echo "<pre>";
print_r($data);
echo "</pre>";
?>
every time it gives json error.
but echo $_REQUEST['data'] gives the correct json data.
plz help.