1

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
?>
2

1 Answer 1

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);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.