use php to parse json data posted from another php file

Posted by akshay.is.gr8 on Stack Overflow See other posts from Stack Overflow or by akshay.is.gr8
Published on 2011-01-02T14:57:11Z Indexed on 2011/01/04 7:53 UTC
Read the original article Hit count: 307

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about JSON