Q:

How to parse https url that redirects to another url

I am trying to parse this URL
https://graph.facebook.com/4/picture?width=378&height=378
but it redirects me to another link:
https://z-n.ak.fbcdn.net/profile.ak/hprofile-ak-xfp1/v/t1.0-1/p480x480/10390028_10102210419817761_5871103530921178170_n.jpg?oh=9d44ae6370a6481a6e4e5c42d7850e2a&oe=56C84426&gda=1455827889_efa267e73eea3dd27aa02526c323a1e6
So the question is I want to implement the code to use the first link and when it redirects to the second link, parse the second one I need to get something from the second URL, what is the best practice?
Thanks for help in advance

A:

With CURL:
$url = 'https://graph.facebook.com/4/picture?width=378&height=378';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow the redirects
curl_setopt($ch, CURLOPT_HEADER, false); // no needs to pass the headers to the data stream
curl_setopt($ch, CURLOPT_NOBODY, true); // get the resource without a body
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // accept any server certificate
curl_exec($ch);

// get the last used URL
$lastUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

curl_close($ch);

echo $lastUrl;

