i’m just new in php , curl i wrote a small mediawiki extension that send the recent change . the problem is when is send this data i try to write it in a file but “1” is only what appear i tried to use var_dump but no changes my sender code is :
$wgHooks['RecentChange_save'][] = 'sendto';
function sendto($recentChange){
$serialized_data=serialize($recentChange);
$con=curl_init();
curl_setopt( $con, CURLOPT_HEADER, true );
curl_setopt($con,CURLOPT_URL,"http://localhost/test.php");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($con,CURLOPT_POSTFIELDS,"data={$serialized_data}");
$result=curl_exec($con);
if($result){
return true ;
}
else
return false ;
curl_close($con);
}
and the another code is (which recive):
$a = unserialize($_POST['data']);
$d=fopen("log.txt","w");
fwrite($d,print_r($a));//only "1" is written
fclose($d);
i think it’s a silly question but i get stuck and need help .
thank you
Instead of
try
By passing
trueas the second argument you instructprint_rto capture (i.e. return) the output instead of printing it.Alternatively, you could use
var_export($a, true)instead ofprint_r()(for a different representation; I only mention it because you were trying to usevar_dump()initially).