I am trying to take a list of URL's from a textbox, it has 1 URL per line and each URL does a redirect, I am trying to get the URL that it redirects to.
When I run this code below on a single URL, it returns the redirected URL which is what I want...
function getRedirect($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
$info = curl_getinfo($ch); //Some information on the fetch
curl_close($ch);
echo '<pre>';
print_r($info);
echo '</pre>';
}
$url = 'http://www.domain.com/go?a:aHR0cDovL2xldGl0Yml0Lm5ldC9kb3d';
getRedirect($url);
Now my problem is when I try to run it on multiple URL's with this code...
if(isset($_POST['urls'])){
$rawUrls = explode("\n", $_POST['urls']);
foreach ($rawUrls as $url) {
getRedirect($url);
}
}
When I run it on my list of URL's instead of giving me the redirected URL like my first example does correctly, it instead gives me the URL that I passed into cURL.
Can someone help me figure out why or how to fix this please?
var_dump($rawUrls)before the foreach loop shows?array(10) { [0]=> string(117) "http://www.url.com/go?a:aHR0cDovL2xvc3RwaWMubmV0L2ltYWdlcy9lMDM1MzgxMjNiYWU0NGUzYjM1ODk3NjFlMWFkN2Y3Ny5qcGc= " [1]=> string(145) "http://www.url.com/go?a:aHR0cDovL3NoYXJlZmxhcmUubmV0L2Rvd25sb2FkLzgyNTYyLjhkZWQwYWQyY2U4NWEzMmJlN2E0MDZlNWY0YmYvQW44OGdlbDAzLndtdi5odG1s " [2]=> string(61) "http://www.url.com/go?a:aHR0cDovL3VsLnRvL2s5Mjh5MHRu " etc...etc...trim()on the urlgetRedirect(trim($url));