0

I want to access a third-party URL with a few POST parameters to get some additional service.

As an example say I have to call http:\www.aaaaaa.com\Add.php with two numbers with POST parameters to get the summation of them. Then it will return the results.

<?php
if (isset($_POST['num1']) && isset($_POST['num2']) ) {
echo $_POST['num1']+$_POST['num2'];
}
?>

Is there possible to access that URL from PHP code in another server like ( http:\www.bbbbb.com\sum.php) without using javascript.

<?php
$num1=13;
$num2=14;
//want to get the summation of 13+14 using above service without using javascripts
?>
virajs
  • 23
  • 1
  • 4
  • 1
    Does this answer your question? [PHP + curl, HTTP POST sample code?](https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code) – Greg Schmidt Jan 19 '20 at 19:29
  • look at this link, https://stackoverflow.com/questions/23416879/call-php-file-located-in-another-server-with-parameter-and-read-variable-values – Premlatha Jan 20 '20 at 01:32

1 Answers1

0

You use use CURL to post to another website. The following code will send two variable to http://www.aaaaaa.com/Add.php, num1 with a value of 13, and num2 with a value of 14.

The data returned from that site will be stored in the variable $returndata

<?php
$urltopost = "http://www.aaaaaa.com/Add.php";
$datatopost = array ("num1" => 13,
"num2" => 14);
 $ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec ($ch);
?>