title: Sending 'X-Requested-With: XMLHttpRequest' and other headers via CURL - other ways?
body: <p>I have, of course, read several questions with exactly this asked, but I have to say it didn't work for me at all. What I am about to accomplish is</p>
  
  <ul>
  <li>sending 'X-Requested-With: XMLHttpRequest' header via PHP and curl</li>
  <li>sending other http request headers via PHP and curl</li>
  </ul>
  
  <p>provided solutions didn't work for me.</p>
  
  <p><strong>How do I know I'm not sending right http request headers?</strong></p>
  
  <p>Simply by </p>
  
  <p>(1)comparing real headers generated by XMLHttpRequest(triggering JQuery click) and those simulated by PHP and curl in Firefox add-on Live HTTP headers</p>
  
  <p>(2)Print_r() -ing $_SERVER variable in target script</p>
  
  <p><strong>What do I get that is incorrect/below my expectations?</strong></p>
  
  <p>First and most important: 
  Firefox Live HTTP headers does not capture my headers (just like they don't exists).</p>
  
  <p>Second, by print_r($_SERVER):</p>
  
  <p>if I get anything of simulated headers at all, I get <code>[HTTP_X_REQUESTED_WITH] =&gt; XMLHttpRequest</code> - <strong>not the:</strong> <code>[X_REQUESTED_WITH] =&gt; XMLHttpRequest</code>. 
  That problem persists almost for any header I send via curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_header) - any of these is being prefixed with 'HTTP' ('Header1: value1' - I get 'HTTP_HEADER1').</p>
  
  <p>I'm using XAMPP with PHP version 5.4.7, CURL 7.24.0 .</p>
  
  <p>Before I ask if what I'm trying to accomplish is possible or maybe not and say thanks in advance for responses, it's not bad idea to provide my code - <em>one of many</em> code solutions that I've tried.</p>
  
  <pre><code>$curl_header = array('X-Requested-With: XMLHttpRequest');
  $data = "name=miloshio"; // just to be sure I'm doing the POST request
  $ch = curl_init('http://example.com/test.php');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_header);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  curl_setopt($ch, CURLOPT_VERBOSE, true);
  $result = curl_exec($ch);
  echo $result;
  </code></pre>
  
  <p>Sum of my questions:</p>
  
  <ol>
  <li>Is it possible to send exactly 'X-Requested-With: XMLHttpRequest'
  header via PHP and curl?</li>
  <li>Is it possible to avoid attaching 'HTTP_' prefix to custom headers
  send by PHP and curl?</li>
  <li>Are there well-known limitations in matter of using PHP and curl?</li>
  </ol>