I have integration with other servers using API
but I can not get value from the response header to complete authentication and get the session of the server
I try this code
$init = curl_init();
$Auth = [];
$response_headers = [];
$header_callback = function($init,$Auth) use (&$response_headers){
$len = strlen($Auth);
$response_headers[] = $Auth;
return $len;
};
curl_setopt_array($init, [
CURLOPT_URL => 'http://ip-api/v1/rest/auth',
CURLOPT_HEADER => true,
CURLOPT_HEADERFUNCTION => $header_callback
]);
$output = curl_exec($init);
$info = curl_getinfo($init);
var_dump($Auth);
echo $Auth[0];
curl_close($init);
but the result is
Warning: Undefined array key 0 in //path
how can get this value
2
Answers
You are looking this php function, if I understand right
apache_request_headers()
.If you have apache this will work. An you will get an array with your headers that you can loop over and take the
['Auth-Nonce']
key. If apache doesn’t have the$header['Auth-Nonce']
in the specific HTTP call,null
will be returned.In case of Nginx and other webservers try this
getallheaders()
. If you get an error that says the function doesn’t exist do it custom like this:In any case you will get your webserver headers on your call.
The data you need is within
$response_headers
, not$Auth
.e.g.
would get you the specific value.