Issue
I want to call the API URL of another website in PHP file. The URL is:
href="http://otherwebsite.com/api/web2sms.php?workingkey=YourKey&to=DestinationNumber&sender=Source&message=HELLO" rel="nofollow noreferrer">http://otherwebsite.com/api/web2sms.php?workingkey=YourKey&to=DestinationNumber&sender=Source&message=HELLO
My code:
<?php
$workingkey = "YourKey";
$to = "DestinationNumber";
$sender = "Source";
$message = "HELLO";
$url = "http://otherwebsite.com/api/web2sms.php?workingkey=$workingkey&to=$to&sender=$sender&message=$message";
$this = execute($url);
?>
I think many things are missing. So please tell me how to make a susscessful API call...
Solution
Simplest way, but need php option allow_url_fopen to be enabled (it is by default, but somehosting disable it) is to use file_get_contents function so it would be just
$result = file_get_contents($url);
If that option is anavailale or you need more complicated request I will offer you to use curl extention. It's usually enabled and in your simple case you can use it like
$ch = curl_init("http://www.example.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
Answered By - SeriousDron Answer Checked By - Candace Johnson (WPSolving Volunteer)