2016-09-16 22 views
0

我想從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_V6CURL_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); 
?> 
+0

什麼捲曲庫是PHP中使用? curres添加了'ipresolve' 7.10.8 –

+0

除了@MarcB提到的,你還需要PHP 5.3+ – apokryfos

+0

@MarcB curl 7.15.5 –

回答

0

是PHP版本5.3+和捲曲版本7.10.8, 加入該捲曲的選擇,因爲你正在使用支持它,你既可以捲曲版本:

1)升級你的PHP版本(從5.2開始推薦有一些問題,使你的網站容易受到攻擊)

2)使用這些常量的實際數值。這些可以在cURL源代碼https://github.com/curl/curl/blob/master/include/curl/curl.h中找到,你應該理想的爲你的cURL版本找到相應的文件,但是我懷疑常量每個版本會得到不同的數字。

IPRESOLVE似乎是和值113和IPRESOLVE_V4是1,因此你會做這樣的事情:

curl_setopt($curl_session,113,1);