使用PHP调用一个sendOTP API时出错

I am getting error while calling one API using PHP.

Error:

Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /opt/lampp/htdocs/test/otp.php on line 8

Warning: include(http://api.msg91.com/api/sendotp.php?authkey="15529*************"&mobile="9937229853"&message="Your verification code is:1111"&sender="Subhrajyoti"&otp="1111"): failed to open stream: no suitable wrapper could be found in /opt/lampp/htdocs/test/otp.php on line 8

Warning: include(): Failed opening 'http://api.msg91.com/api/sendotp.php?authkey="15529*************"&mobile="9937229853"&message="Your verification code is:1111"&sender="Subhrajyoti"&otp="1111"' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/test/otp.php on line 8

I am explaining my code below.

$authkey="15529*************";
$mobile=9937229853;
$code=1111;
$message="Your verification code is:".$code;
$sender="Subhrajyoti";
$otp=1111;
include ('http://api.msg91.com/api/sendotp.php?authkey="'.$authkey.'"&mobile="'.$mobile.'"&message="'.$message.'"&sender="'.$sender.'"&otp="'.$otp.'"');

Here I am trying to send OTP but getting those message. Here I need to send OTP and get the response.

you can use CURL or file_get_contents.

$response = file_get_contents('http://api.msg91.com/api/sendotp.php?authkey="'.$authkey.'"&mobile="'.$mobile.'"&message="'.$message.'"&sender="'.$sender.'"&otp="'.$otp.'"');
$response = json_decode($response);

or using cURL:

$ch = curl_init();
$data=array('authkey'=>$authkey,'mobile'=>$mobile,'message'=>$message);//all parameter
curl_setopt($ch, CURLOPT_URL, 'http://api.msg91.com/api/sendotp.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);

Instead of this line:

include ('http://api.msg91.com/api/sendotp.php?authkey="'.$authkey.'"&mobile="'.$mobile.'"&message="'.$message.'"&sender="'.$sender.'"&otp="'.$otp.'"');

use cURL to hit the url appended with the message and mobile number and get the response from it. And don't forget to encode the entire url by using urlencode() function.

Ex:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$APIresponse = curl_exec($ch);
curl_close($ch);
$res = json_decode($APIresponse, true);