// From URL to get redirected URL
$url = 'https://www.shareasale.com/m-pr.cfm?merchantID=83483&userID=1860618&productID=916465625';
$ch = curl_init(); // create cURL handle (ch)
if (!$ch) {
die("Couldn't initialize a cURL handle");
}
// set some cURL options
$ret = curl_setopt($ch, CURLOPT_URL, $url);
$ret = curl_setopt($ch, CURLOPT_HEADER, 1);
$ret = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_setopt($ch, CURLOPT_TIMEOUT, 30);
// execute
$ret = curl_exec($ch);
if (!empty($ret)) {
$info = curl_getinfo($ch);
curl_close($ch); // close cURL handler
if (empty($info['http_code'])) {
die("No HTTP code was returned");
} else {
echo 'REDIRECTED FINAL URL'.$info['url']); // this does not give final url.
}
}
is their any way we can get final url from a url after all re-directions ? Let me know if any changes needs to be done in this code ?
https://www.shareasale.com/m-pr.cfm?merchantID=83483&userID=1860618&productID=916465625
This is the url which has lots of redirections, i am testing code with this one but it does not return final url, it return some the url then the url which you see in url bar.