简体   繁体   English

IPRESOLVE的PHP curl_setopt错误

[英]PHP curl_setopt error with IPRESOLVE

I am trying to send information from MySQL database to Android users using PHP. 我正在尝试使用PHP从MySQL数据库向Android用户发送信息。 My code works very well when I use my localhost and I have notification to my app, but when I am using the online free hosting (000webhost), I get the following error: 当我使用本地主机并通知我的应用程序时,我的代码工作得很好,但是当我使用在线免费托管(000webhost)时,出现以下错误:

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()[function.curl-setopt]:第24行的/home/a2275966/public_html/send_notification.php中无效的curl配置选项包含以下代码:24

curl_setopt($curl_session,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);

I tried to use CURL_IPRESOLVE_V6 or CURL_IPRESOLVE_WHATEVER but didn't work. 我尝试使用CURL_IPRESOLVE_V6CURL_IPRESOLVE_WHATEVER但是没有用。 Is this a limitation in the hosting website, or is there something missing in my code? 这是托管网站的限制,还是我的代码中缺少某些内容? The curl version is 7.15.5 and the PHP version is 5.2.17 on the free host. 在免费主机上,curl版本为7.15.5 ,PHP版本为5.2.17

Here is my code: 这是我的代码:

<?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);
?>

This cURL option was added in PHP version 5.3+ and cURL version 7.10.8, since you are using a cURL version which supports it you can either: 此cURL选项是在PHP 5.3+版本和cURL版本7.10.8中添加的,因为您使用的cURL版本支持该选项,您可以:

1) Upgrade your PHP version (recommended since 5.2 has some issues which make your site vulnerable to exploits) 1)升级您的PHP版本(由于5.2存在一些使您的网站容易受到攻击的问题,因此推荐使用)

2) Use the actual numeric values of those constants. 2)使用这些常数的实际数值。 Those can be found in the cURL source at https://github.com/curl/curl/blob/master/include/curl/curl.h you should ideally find the equivalent file for your cURL version but I doubt constants would get different numbers per version. 这些可以在cURL源中找到, 网址https://github.com/curl/curl/blob/master/include/curl/curl.h。理想情况下,您应该找到与您的cURL版本等效的文件,但我怀疑常量会有所不同每个版本的编号。

IPRESOLVE seems to be value 113 and IPRESOLVE_V4 is 1 so you'd do something like: IPRESOLVE似乎是值113,而IPRESOLVE_V4是1,因此您应该执行以下操作:

curl_setopt($curl_session,113,1); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM