Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Trace Redirect

Tags:

php

I have a database of over 10,000 URL's, however every single one of them redirects to another URL. How can I request a URL and find out it's final destination in a path of (possibly) multiple redirects?

like image 669
zuk1 Avatar asked Dec 18 '25 00:12

zuk1


1 Answers

You can do it using the cURL functions:

$c = curl_init('http://original.url');
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_exec($c);

// Error checking here - see curl_error()

$newUrl = curl_getinfo($c, CURLINFO_EFFECTIVE_URL);

curl_close($c);
like image 140
Greg Avatar answered Dec 19 '25 12:12

Greg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!