Q:

How can I download the .zip of my private github repository using cURL on php?

I want to download the latest zip version of a private github repository I'm working on, and I want to do this using a PHP script. However, my current PHP script is just returning "Not Found" - I'm guessing I have an issue with my cURL user/pass setup, but I can't figure it out. My current code is as follows:
$username='XXX';
$password='XXX';
$URL='https://github.com/[user]/[reponame]/archive/master.zip';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result=curl_exec ($ch);

file_put_contents('master.zip', $result);
curl_close ($ch);

A:

I was able to get it to work by separating the login page and the file download page into two requests. The following code worked for me:
$username='XXX';
$password='XXX';
$URL='https://github.com/[user]/[reponame]/archive/master.zip';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://github.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$result=curl_exec ($ch);
curl_close ($ch);

file_put_contents('master.zip', $result);

