Download a ZIP file using cURL
<p>I am trying to download a ZIP file using cURL, from a given URL.
I received an URL from a supplier where I should download a ZIP file. But everytime I try to download the ZIP file I get the page that says that I am not logged in.</p>

<p>The url where I should get the file from looks like this:</p>

<pre><code>https://www.tyre24.com/nl/nl/user/login/userid/USERID/password/PASSWORD/page/L2V4cG9ydC9kb3dubG9hZC90L01nPT0vYy9NVFE9Lw==
</code></pre>

<p>Here you see that the USERID, and PASSWORD are variables that are filled in with the correct data. The strange thing is that if I enter the URL in my browser it seems to work, the zip file is getting downloaded.</p>

<p>But everytime I call that URL with cURL, I seem to get a incorrect login page. Could someone tell me what I am doing wrong?</p>

<p>It seems like that there is a redirect behind the given URL, that is why I have putted in the cURL call: <code>curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);</code></p>

<p>Here is my code:</p>

<pre><code>set_time_limit(0);

//File to save the contents to
$fp = fopen ('result.zip', 'w+');

$url = "https://www.tyre24.com/nl/nl/user/login/userid/118151/password/5431tyre24/page/L2V4cG9ydC9kb3dubG9hZC90L01nPT0vYy9NVFE9Lw==";

//Here is the file we are downloading, replace spaces with %20
$ch = curl_init(str_replace(" ","%20",$url));

curl_setopt($ch, CURLOPT_TIMEOUT, 50);

//give curl the file pointer so that it can write to it
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$data = curl_exec($ch);//get curl response

//done
curl_close($ch);
</code></pre>

<p>Am I doing something wrong?</p>