title: Why is cURL doesn't behave the same as the web browser
body: <p>I'm using cURL to fetch a website. I can get the login page and use cURL to login sending the credential details over a POST Form successfully. When I try to get the next page which is done using GET (as my web browser reports it in the Network Section of debugging utilities, the web browser show me the page you normally see but cURL show me another page (a login page). I have cookies enabled in my cURL scripts. I tried disabling Javascript in case it was playing with cookies but it still worked in the browser without it. What else am I missing?</p>
  
  <p>Here are my curl scripts:</p>
  
  <pre><code>function HttpGet($url)
  {
      $header = array();
      $header[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
      $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: ';
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
  
      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)');
      curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
      curl_setopt($ch, CURLOPT_AUTOREFERER, true);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_ENCODING, '');
      curl_setopt($ch, CURLOPT_TIMEOUT, 60);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($ch, CURLOPT_COOKIESESSION, true);
      curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
      curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  
      if (! $html_content = curl_exec($ch))
      {
          trigger_error(curl_error($ch)); 
      }
  
      echo "CURLINFO_EFFECTIVE_URL: " . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL) . "\n";
      echo "CURLINFO_HTTP_CODE: " . curl_getinfo($ch, CURLINFO_HTTP_CODE) . "\n";
  
      curl_close ($ch);
      return $html_content;
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>function HttpPost($address, $fields, $outputFilename, $currentUrl)
  {
      $header = array();
      $header[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
      $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: ';
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $address);
      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)');
      curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
      curl_setopt($ch, CURLOPT_AUTOREFERER, true);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_ENCODING, '');
      curl_setopt($ch, CURLOPT_TIMEOUT, 60);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      curl_setopt($ch, CURLOPT_COOKIESESSION, true);
      curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
      curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  
      foreach($fields as $key=&gt;$value) { $fields_string .= $key.'='.$value.'&amp;'; }
      $fields_string = rtrim($fields_string, '&amp;');
  
      curl_setopt($ch,CURLOPT_POST, count($fields));
      curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
  
      if (! $html_content = curl_exec($ch))
      {
          trigger_error(curl_error($ch)); 
      }
  
      $currentUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
      echo "CURLINFO_EFFECTIVE_URL: " . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL) . "\n";
      echo "CURLINFO_HTTP_CODE: " . curl_getinfo($ch, CURLINFO_HTTP_CODE) . "\n";
  
      curl_close ($ch);
      return $html_content;
  }
  </code></pre>