Answer the question
In order to leave comments, you need to log in
Why is PHP variable value not being sent via POST?
You need to send a request to a site of the following type: site.ru/text?AAA=aaa&BBB=bbb&CCC=ccc, and before that, ask the user for these same aaa, bbb, ccc.
Learned through the form, recorded in the variables $a, $b, $c.
We made a common variable: $send = site.ru/text?AAA=$a&BBB=$b&CCC=$c It
remains to send this very variable using the POST or GET method to another site.
To be on the safe side, I display the value of the $send variable to check what we have collected from the forms. The value is always true, and if you copy it and paste it into the address bar, then the recipient will process this command.
It remains to try to force the script to send this data on its own.
I tried to do without cURL first, deducted the transfer method via sockets - did not work.
Then I decided to connect cURL, but still I get the same answer: the first parameter (AAA) is not specified. I suppose something cuts off everything after /?, because if you enter the URL just site.ru (without /text/) for interest, then the main page of the site starts in response.
Here is an example of sending a value (by the way, it is taken from a similar question on the toaster, and I tried a lot of other examples from other sites - nothing works).
$myCurl = curl_init();
curl_setopt_array($myCurl, array(
CURLOPT_URL => 'http://site.ru/text/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(array($send))
));
$response = curl_exec($myCurl);
curl_close($myCurl);
echo "Ответ на Ваш запрос: ".$response;
Answer the question
In order to leave comments, you need to log in
So you send "site.ru/text?AAA=$a&BBB=$b&CCC=$c" as POST parameters. Of course the server will swear.
You need to do this:
$send = array(
'aaa' => $a,
'bbb' => $b,
'ccc' => $c
);
$myCurl = curl_init();
curl_setopt_array($myCurl, array(
CURLOPT_URL => 'http://site.ru/text/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(array($send))
));
$response = curl_exec($myCurl);
curl_close($myCurl);
echo "Ответ на Ваш запрос: ".$response;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question