0

If we have an URL say firsturl.com is redirected to secondurl.com to thirdurl.com to fourthurl.com(Destination Url).

How can we display secondurl.com,thirdurl.com and fourthurl.com using JavaScript or PHP.

I am using PHP script curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); to find out the destination URL,I also want to display second URL and third URL.

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • Hi! What have you tried so far? – Joël Jan 12 '17 at 09:34
  • function get_redirect_final_target($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow redirects curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // set referer on redirect curl_exec($ch); $target = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); curl_close($ch); if ($target) return $target; return false; } – Madhan Kumar Jan 12 '17 at 09:44
  • @MadhanKumar why didn't you post as an answer? it's hard to read code that long in a comment. – fpietka Jan 12 '17 at 10:07
  • @fpietka I can able to get only final url,How can we get second url and third url – Madhan Kumar Jan 12 '17 at 11:01
  • 1
    @MadhanKumar please add your code in the question itself, so it'll be more readable for everybody. – fpietka Jan 12 '17 at 14:37
  • @MadhanKumar see http://stackoverflow.com/questions/7230002/show-curl-redirection-but-dont-follow you shouldn't set `CURLOPT_FOLLOWLOCATION` – fpietka Jan 12 '17 at 15:13

0 Answers0