title: PHP cURL results in 403 Forbidden
body: <p>I am trying to cURL a remote site that results in a 403 Forbidden error. From the same server I can run the following two commands via Terminal. The first fails while the second works. How can I get my PHP code to match up to the second terminal command?</p>
  
  <p>This Terminal command results in nothing returned.</p>
  
  <pre><code>curl http://www.barneys.com
  </code></pre>
  
  <p>This Terminal command results in a proper result (the HTML of the page)</p>
  
  <pre><code>curl -L http://www.barneys.com
  </code></pre>
  
  <p>My PHP Code:</p>
  
  <pre><code>$ch = curl_init('http://www.barneys.com');
  $http_headers = array(
  'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:40.0)' . 'Gecko/20100101 Firefox/40.0',
  'Accept: */*',
  'X-Requested-With: XMLHttpRequest',
  'Referer: http://www.barneys.com', # IMPORTANT
  'Accept-Language: pt-BR,en-US;q=0.7,en;q=0.3',
  );
  curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
  curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_REFERER, 'http://www.barneys.com');
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); 
  curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  $response = curl_exec($ch);
  $redirectURL = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
  curl_close($ch);
  
  echo $response;
  </code></pre>
  
  <p><strong>EDIT:</strong> Here is the log from the cURL request via PHP:</p>
  
  <pre><code>* About to connect() to www.barneys.com port 80 (#0)
  *   Trying 23.204.27.110... * connected
  * Connected to www.barneys.com (23.204.27.110) port 80 (#0)
  &gt; GET / HTTP/1.1
  Host: www.barneys.com
  User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:40.0)Gecko/20100101 Firefox/40.0
  Accept: */*
  X-Requested-With: XMLHttpRequest
  Referer: http://www.barneys.com
  Accept-Language: pt-BR,en-US;q=0.7,en;q=0.3
  Connection: keep-alive
  
  &lt; HTTP/1.1 403 Forbidden
  &lt; Server: AkamaiGHost
  &lt; Mime-Version: 1.0
  &lt; Content-Type: text/html
  &lt; Content-Length: 265
  &lt; Expires: Mon, 11 Apr 2016 23:22:16 GMT
  &lt; Date: Mon, 11 Apr 2016 23:22:16 GMT
  &lt; Connection: close
  &lt; 
  * Closing connection #0
  </code></pre>