I need to retrieve the redirect URL from a link, but when I pull the header information it just returns:
Locations: redirecting...
Afterwards, the page is redirected to the URL I want to redeem. I'm using the code:
$url = 'http://168.0.51.253:8000/boleto/74140-P2UTT5T4IH/';
// Final URL I want to retrieve = https://data.galaxpay.com.br/prooverisp/boleto/202109YB0K77L7WYP5PPY0NGT6DMKOD01155936
$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);
curl_close($ch);
$headers = explode("\n", $a);
$j = count($headers);
$ticket = null;
for ($i = 0; $i < $j; $i++) {
if (strpos($headers[$i], "Location:") !== false) {
$ticket = trim(str_replace("Location:", "", $headers[$i]));
break;
}
}
var_dump($headers);
How can I wait for the redirect and retrieve the final URL? I work with PHP.