I got this function to detect a page's redirect final URL
So, if I call the function with google.com it will detect the redirect and bring back http://www.google.co.ve or http://www.google.co.ar, http://www.google.co.il, etc...
This tells me that this is detecting the final URL properly... now when I try with a shortener service like t.co and I use this link as an example... t.co/0BWUquGyj3 it will return t.co/0BWUquGyj3 again, instead of detecting the return URL
function parse_url($url, $user_agent = 'desktop') {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_FILETIME, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, 45);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 45);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_TIMEOUT, 120);
curl_setopt($curl, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
$curl_exec = curl_exec($curl);
$header = curl_getinfo($curl);
$final_url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
curl_close($curl);
return $final_url;
}
#http://t.co/0BWUquGyj3
$cosas = parse_html("t.co/0BWUquGyj3");
echo $cosas; //returns t.co/0BWUquGyj3 instead of the final redirect URL