php - How to get the real URL after file_get_contents if redirection happens? -


i'm using file_get_contents() grab content site, , amazingly works if url pass argument redirects url.

the problem need know new url, there way that?

you might make request curl instead of file_get_contents().

something should work...

$ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_header, true); curl_setopt($ch, curlopt_followlocation, false); curl_setopt($ch, curlopt_returntransfer, true); $a = curl_exec($ch); if(preg_match('#location: (.*)#', $a, $r))  $l = trim($r[1]); 

source


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -