我无法通过curl看到我发布的数据?
我是 php 的新手,curl 我编写了一个小的 mediawiki 扩展来发送最近的更改。问题是何时发送此数据,我尝试将其写入文件中,但“1”只是我尝试使用 var_dump
出现的内容,但没有更改我的发送者代码是:
$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);
}
另一个代码是(哪个接收):
$a = unserialize($_POST['data']);
$d=fopen("log.txt","w");
fwrite($d,print_r($a));//only "1" is written
fclose($d);
我认为这是一个愚蠢的问题,但我陷入困境并需要帮助。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是
尝试
通过传递
true
作为第二个参数,而是指示print_r
捕获(即返回)输出而不是打印它。或者,您可以使用
var_export($a, true)
而不是
print_r()
(用于不同的表示;我只是提到它,因为您最初尝试使用var_dump()
)。Instead of
try
By passing
true
as the second argument you instructprint_r
to 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).