title: Curl request with digest auth in PHP for download Bitbucket private repository
body: <p>I'm try to do this request on php, for download the last source from my Bitbucket private repository:</p>
  
  <pre><code>curl --digest --user user:pass https://bitbucket.org/user/repo/get/tip.zip -o test.zip
  </code></pre>
  
  <p>in command line its ok, the file download perfect, but in php dont work, this my php code:</p>
  
  <pre><code>$out = fopen('test.zip', 'w+');
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_VERBOSE, true);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
  curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_FILE, $out);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_NOBODY, false);
  curl_setopt($ch, CURLOPT_URL, 'https://bitbucket.org/user/repo/get/tip.zip');
  curl_exec($ch);
  </code></pre>
  
  <p>This is the response, the login its invalid and the server redirect to the login page:</p>
  
  <pre><code>Error CURL: '' 
  Error number: 0
  Array
  (
      [url] =&gt; https://bitbucket.org/account/signin/?next=/user/repo/get/tip.tar.gz
      [content_type] =&gt; text/html; charset=utf-8
      [http_code] =&gt; 200
      [header_size] =&gt; 1099
      [request_size] =&gt; 194
      [filetime] =&gt; -1
      [ssl_verify_result] =&gt; 0
      [redirect_count] =&gt; 1
      [total_time] =&gt; 1.055465
      [namelookup_time] =&gt; 1.5E-5
      [connect_time] =&gt; 0.102969
      [pretransfer_time] =&gt; 0.216164
      [size_upload] =&gt; 0
      [size_download] =&gt; 10049
      [speed_download] =&gt; 9520
      [speed_upload] =&gt; 0
      [download_content_length] =&gt; 10049
      [upload_content_length] =&gt; 0
      [starttransfer_time] =&gt; 0.527512
      [redirect_time] =&gt; 0.527519
      [redirect_url] =&gt; 
  )
  </code></pre>
  
  <p>Anyone know how I can solve my problem?
  Thank you very much!!!</p>