title: Getting error code 28 with cURL
body: <p><strong>THIS HAS BEEN SOLVED - SEE ANSWER AT THE END OF THIS POST</strong></p>
  
  <p>I am trying to retrieve data from a remote server using PHP / cURL</p>
  
  <p>If I put the following URL into a browser the data comes back correctly.</p>
  
  <p><a href="http://realm103.c7.castle.wonderhill.com/api/map.json?user%5Fid=5245274&amp;x=375&amp;y=375&amp;timestamp=1310554325&amp;%5Fsession%5Fid=5b2070a46a083a33e053d60dbc2d062e&amp;dragon%5Fheart=098d2deb0a37f18c97428d636c456572f9bade24&amp;version=3" rel="nofollow">http://realm103.c7.castle.wonderhill.com/api/map.json?user%5Fid=5245274&amp;x=375&amp;y=375&amp;timestamp=1310554325&amp;%5Fsession%5Fid=5b2070a46a083a33e053d60dbc2d062e&amp;dragon%5Fheart=098d2deb0a37f18c97428d636c456572f9bade24&amp;version=3</a></p>
  
  <p>However when I try to access if with PHP / cURL it just times out (error code 28).</p>
  
  <pre><code>$json = curl($jsonurl, $realm['intRealmID'], $realm['strRealmServer']);
  
  function curl($url, $realm, $realmServer){
  $header = array();
  $header[] = 'Host: realm'.strval($realm).'.'.$realmServer.'.castle.wonderhill.com';
  $header[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
  $header[] = 'Accept-Language: en-us,en;q=0.5';
  $header[] = 'Accept-Encoding: gzip,deflate';
  $header[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
  $header[] = 'Connection: keep-alive';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0');
  curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_ENCODING, '');
  curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  return curl_exec($ch);
  curl_close($ch);
  </code></pre>
  
  <p>}</p>
  
  <p>Anybody have any ideas why it works from the browser but not via cURL? Thanks</p>
  
  <p>ADDITIONAL INFO
  Whilst cURL isn't working for the URL above. For the URL below it works just fine. The only difference is the server the data is being requested from. The data itself and POST is identical.</p>
  
  <p><a href="http://realm4.c5.castle.wonderhill.com/api/map.json?user%5Fid=1053774&amp;x=375&amp;y=375&amp;timestamp=1310616808&amp;%5Fsession%5Fid=5b2070a46a083a33e053d60dbc2d062e&amp;dragon%5Fheart=f35f476facab91f0e901eaf2209a0c8a9b9bedcc&amp;version=3" rel="nofollow">http://realm4.c5.castle.wonderhill.com/api/map.json?user%5Fid=1053774&amp;x=375&amp;y=375&amp;timestamp=1310616808&amp;%5Fsession%5Fid=5b2070a46a083a33e053d60dbc2d062e&amp;dragon%5Fheart=f35f476facab91f0e901eaf2209a0c8a9b9bedcc&amp;version=3</a></p>
  
  <p><strong>ANSWER</strong></p>
  
  <p>Finally back to this and found that the referrer was the problem. The server was expecting to see no referrer in the request header. When it did the request was blocked. That behaviour probably was not consistent across all servers at the time but it is now. Removing the referrer from the request header and leaving everything else the same now works.</p>