0

I want to call the API URL of another website in php file. The URL is:

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...

Rasclatt
  • 12,498
  • 3
  • 25
  • 33

2 Answers2

1

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);
SeriousDron
  • 1,296
  • 9
  • 12
0

Read about CURL or Guzzle.

I recommend You Guzzle.

Guzzle Github

There is some example covers your needs.

Rysiu
  • 104
  • 1
  • 9