title: PHP Curl Download Issues
body: <p>I have a function that takes as input an array of url's. I have verified that the url's are correct and I can loop through them perfectly. I also verified using curl_getinfo that curl is downloading the correct pages. However, the output of curl (html) is the same for every page. Here is my code:</p>
  
  <pre><code>          $urls = array();
       $urls = getpages($mainpage);
       print_r($urls);
       foreach($urls as $link) {
           echo $link. '&lt;br&gt;&lt;br&gt;&lt;br&gt;';
           $circdl = my_curl($link);
           echo $circdl. '&lt;br&gt;&lt;br&gt;&lt;br&gt;';
           $circdl = NULL;
       }
  </code></pre>
  
  <p>The outputted array of url's is as follows:</p>
  
  <pre><code> Array ( [0] =&gt; http://www.site.com/savings/viewcircular?promotionId=81498&amp;sneakpeek=&amp;currentPageNumber=1 [1] =&gt; http://www.site.com/savings/viewcircular?promotionId=81498&amp;sneakpeek=&amp;currentPageNumber=2
  </code></pre>
  
  <p>$link also outputs appropriately as does curl in curl_getinfo. I have ran another array of url's thru this loop and they work fine but I suspect the issue here is with the format of the url (ampersands). I'm really stumped why these pages aren't downloading as expected.</p>
  
  <p>Here's the my_curl function:</p>
  
  <pre><code> function my_curl($url)
   {
  $timeout=10;
  $error_report=TRUE;
  $curl = curl_init();
  $cookiepath = drupal_get_path('module','mymodule'). '/cookies.txt';
  
  // HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
  $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  $header[] = "Cache-Control: max-age=0";
  $header[] = "Connection: keep-alive";
  $header[] = "Keep-Alive: 300";
  $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
  $header[] = "Accept-Language: en-us,en;q=0.5";
  $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE BLANK
  
  // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
  curl_setopt( $curl, CURLOPT_URL,            $url  );
  curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'  );
  curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
  curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
  curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
  curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
  curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
  curl_setopt( $curl, CURLOPT_COOKIEFILE,     $cookiepath );
  curl_setopt( $curl, CURLOPT_COOKIEJAR,      $cookiepath );
  curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );
  
  // RUN THE CURL REQUEST AND GET THE RESULTS
  $htm = curl_exec($curl);
  
  // Check for page request
  
  //$info = curl_getinfo($curl);
  //echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
  
  // ON FAILURE HANDLE ERROR MESSAGE
  if ($htm === FALSE)
  {
      if ($error_report)
      {
          $err = curl_errno($curl);
          $inf = curl_getinfo($curl);
          echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
          var_dump($inf);
      }
      curl_close($curl);
      return FALSE;
  }
  
  // ON SUCCESS RETURN XML / HTML STRING
  curl_close($curl);
  return $htm;
  </code></pre>
  
  <p>}</p>
  
  <p>What's very interesting is that if I run this:</p>
  
  <pre><code> echo my_curl('http://www.site.com/savings/viewcircular?promotionId=81498&amp;sneakpeek=&amp;currentPageNumber=2')
  </code></pre>
  
  <p>The output is correct!!??:(</p>
  
  <p>Thanks for any help!</p>