To download a file from a third-party website, I use code similar to that in the first section below. The token is necessary, and the download will not proceed if it is invalid. With my own site, I wish to replicate that action. Although I am in charge of both the transmitting and receiving servers, I am unable to make this function. Please tell me what I'm doing incorrectly.
The code on the sending server:
$url = "https://example.com/download/index.php?token=$someid";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
curl_exec($ch);
try {
if(curl_errno($ch)){
throw new Exception(curl_error($ch));
}
}
catch (Exception $e){ echo $e->getMessage(); }
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($statusCode == 200) {
handle the downloaded file
} else {
echo 'Result = '. $statusCode;
}
And this is on my website (the receiving server). When I run the code above, I should get a 404 error, but all I get is "Result =" because the true is only there for testing.
if (true || ! empty($_GET['token'])) {
header("HTTP/1.1 404 Not Found");
exit;
}
header("Location: http://example.com/myfile.zip");
exit;
Can someone please help me with this?