I am trying to get information from an API. I would like to be able to get the "Location:" property from the API response and capture it as a variable in PHP.
Here is a snip from the API docs so you know what I am talking about:
Read Person Portrait This example request illustrates how to read a description of the portrait for a tree person.
XML Request
GET /platform/tree/persons/KWWM-5R1/portrait
Accept: application/x-fs-v1+xml
Authorization: Bearer YOUR_ACCESS_TOKEN_HERE
ResponseHTTP/1.1 307 Temporary Redirect
Transfer-encoding: chunked
Cache-control: no-transform, must-revalidate, max-age=0
Content-type: application/x-fs-v1+xml
Vary: Accept-Encoding
Vary: Accept, Accept-Language, Accept-Encoding, Expect
Location: /domain/path/to/image
X-processing-time: 1
Content-location: /platform/tree/persons/PPPP-PPP/portrait
I would like to return and capture the Location: value (path to image) as a PHP variable so I can use it as an image source.
I have tried using cURL from another help site but that doesn't return anything (not even an error)
$ch = curl_init();
curl_setopt_array($ch, array(
// set url, timeouts, encoding headers etc.
CURLOPT_URL => 'https://sandbox.familysearch.org/platform/tree/persons/KWWM-5R1/portrait,
// ...
));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer' . $_SESSION['fs-session'],
'Accept: application/x-fs-v1+xml',
));
$respons = curl_exec($ch);
$info = curl_getinfo($ch);
I apologize for asking for too much help, but I am very new to this and was up all night trying to figure it out.
You mean you simply want to get the response headers of a request ? You could use this: http://php.net/manual/en/function.get-headers.php