-2

im try to send variable from a php page to anotherone in diffrent server,but it doesnt work.here is my code.witch part of this i did wrong?

$Phone='09757527255';
$Random='123456';
$data=array("phone"=>$Phone,"random"=>$Random);
$string=http_build_query($data);
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://xxxxxxx.com/xxxxx.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$string);

// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

curl_close ($ch);
farshad
  • 1
  • 3
  • 1
    Does this answer your question? [PHP + curl, HTTP POST sample code?](https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code) – JCWasmx86 Aug 09 '20 at 19:39
  • But it doesnt work for me – farshad Aug 09 '20 at 19:42
  • 1
    "*doesnt work*" is not helpful. What doesnt work. What errors do you get. What results are happening that are not what you wanted. Be helpful, if you want help. – IncredibleHat Aug 09 '20 at 19:45
  • how can i say when i doesnt know!!!i check my destination code with GET and manually send data with url and it was fine.and i catch above code is fine too – farshad Aug 09 '20 at 19:53
  • What happens with this code? Does the other server receive this? Do you get an error? – user3783243 Aug 09 '20 at 20:07
  • no it doesnt receive.i try to put variable in database with destination code but there is nothing to save. – farshad Aug 09 '20 at 20:12

1 Answers1

0

You are sending curl request with CURLOPT_POST set to 1, so you should receive data from $_POST variable. Maybe you are trying to receive it from $_GET variable?

Artur
  • 1