I have this link to download a video to my disk:
https://vip1.truckstore.club/smart_link.php?linkid=208151&username=Nsoah&token=MzIzNTc2&type=tv
I've managed to get the filename of the video but that's not what I need, I wanted to strap the redirect URL that's led to the server returning the filename for download.
I've tried multiple Stackoverflow answers but none seem to be connected to my case. For your reference in case you may flag the question as a possible duplicate:
Get final redirect with Curl PHP
How can I find where I will be redirected using cURL in PHP?
A similar question that was almost same as mine can be found here: How to get final redirect URL in PHP
I tried this code first:
$url = 'https://vip1.truckstore.club/smart_link.php?linkid=208151&username=Nsoah&token=MzIzNTc2&type=tv';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$html = curl_exec($ch);
$redirectedUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
echo "Original URL: " . $url . "<br>";
echo "Redirected URL: " . $redirectedUrl;
But the problem is the original URL is returned as the final URL. Then this is the code that returns the filename of the video:
$curl = curl_init('https://vip1.truckstore.club/smart_link.php?linkid=208151&username=Nsoah&token=MzIzNTc2&type=tv');
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_NOBODY, true);
if (($response = curl_exec($curl)) !== false)
{
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == '200')
{
var_dump($response);
$reDispo = '/^Content-Disposition: .*?filename=(?<f>[^\s]+|\x22[^\x22]+\x22)\x3B?.*$/m';
if (preg_match($reDispo, $response, $mDispo))
{
$filename = trim($mDispo['f'],' ";');
echo "Filename Found: $filename";
}
}
}
curl_close($curl);
Is there a way to get the exact location of the content? Or is the site owner using a script for the redirect? Someone to help me out.