我想從MySQL數據庫發送信息給使用PHP的Android用戶。我的代碼工作得很好,當我用我的本地主機,我必須通知到我的應用程序,但是當我使用網上免費託管(000webhost的),我收到以下錯誤:PHP curl_setopt錯誤與IPRESOLVE
Warning: curl_setopt() [function.curl-setopt]: Invalid curl configuration option in /home/a2275966/public_html/send_notification.php on line 24 line 24 contains this code:
curl_setopt($curl_session,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
我試着使用CURL_IPRESOLVE_V6
或CURL_IPRESOLVE_WHATEVER
但沒有奏效。 這是主機網站的一個限制,還是有我的代碼中缺少的東西?捲曲版本爲7.15.5
,免費主機上的PHP版本爲5.2.17
。
這裏是我的代碼:
<?php
require "init.php";
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm='https://fcm.googleapis.com/fcm/send';
$server_key="AIzaSyBIUnk81EnIIrrlM1FfSxVCHPGqptuf3FQ";
$sql="select fcm_token from fcm_info";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_row($result);
$key=$row[0];
$headers= array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$fields = array('to'=>$key,
'notification'=>array('title'=>$title,'body'=>$message));
$payload=json_encode($fields);
$curl_session=curl_init();
curl_setopt($curl_session,CURLOPT_URL,$path_to_fcm);
curl_setopt($curl_session,CURLOPT_POST,true);
curl_setopt($curl_session,CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl_session,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl_session,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl_session,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
curl_setopt($curl_session,CURLOPT_POSTFIELDS,$payload);
$results=curl_exec($curl_session);
if($results)
echo "donne";
else
echo "nnnooo";
mysqli_close($con);
?>
什麼捲曲庫是PHP中使用? curres添加了'ipresolve' 7.10.8 –
除了@MarcB提到的,你還需要PHP 5.3+ – apokryfos
@MarcB curl 7.15.5 –