0
I’m making a request via Curl as follows (it is only test, not in production)
<?php
$post = [
"Primeiro",
"Segundo"
];
$headers = [
'Terceiro',
'Quarto'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, __DIR__ . '/er.php?teste');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
?>
And I’m trying to get dice AND THE HEADER as follows:
<?php
if ( isset($_GET["teste"]) ) {
print_R ( $_SERVER["headers"] );
print_R ( $_POST );
}
?>
The $_POST receive normally. But I’m not sure how to receive the headers.
I searched the exit print_R ( $_SERVER );
and the key headers there is no.
What should I do to receive the header sent by Curl?
EDIT:
I tried also as below and did not receive the header:
$headers = [
'X-Apple-Tz: 0',
'X-Apple-Store-Front: 143444,12',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept-Language: en-US,en;q=0.5',
'Cache-Control: no-cache',
'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
'Host: www.example.com',
'Referer: http://www.example.com/index.php', //Your referrer address
'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0',
'X-MicrosoftAjax: Delta=true'
];
The array headers should be a array associative, where the key is the header name. The way it did it makes no sense. Fixing this, see if you will receive the value in
$_SERVER["HTTP_<nome>"]
– Woss
Okay. Can you explain to me how to do?
– Carlos Rocha
Do you know what HTTP headers are? You know how to create an associative array?
– Woss
see at the end of the question please. I edited!
– Carlos Rocha
sorry, I do. But I wanted to reduce the amount of text in the question and I got in the way
– Carlos Rocha
I believe this can help you: https://stackoverflow.com/a/9183272/3687410 take a look.
– Juarez Turrini
Put the
print_r($_SERVER)
also– Woss
Yes, but how will print_r($_SERVER) help? if you don’t have neuma $_SERVER co Indice being index of the sent array? I was in doubt!
– Carlos Rocha
And with the name
HTTP_<nome>
, as I quoted in the first comment?– Woss
type like this? print_r ( $_SERVER["HTTP_X-Apple-Tz"] );
– Carlos Rocha
You saw the link I sent above?
– Juarez Turrini
I read yes and did some tests, but what I need does not come out in the variables!
– Carlos Rocha