0

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);

Output for successful filename
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.

  • There is no redirect here, the URL immediately gives a 200 OK response. The filename your browser suggests is not taken from any URL, it is from the `Content-Disposition` header. – CBroe Sep 28 '22 at 07:17
  • Okay, thanks for the reply. So according to you, do you think we'll be able to achieve this? If not, can you conclude that they're actually using a script that CURL won't handle? Thanks once again – Obedgiu Derrick Sep 28 '22 at 20:07
  • You have CURLOPT_NOBODY set to true - that will cause a HEAD request. Set it to false, and you should get the response headers _and_ response body. – CBroe Sep 29 '22 at 06:03

0 Answers0