title: How to verify if "php://input" is set and not empty
body: <p>How to verify if user have posted with XMLHttpRequest some data to PHP?</p>
  
  <p>This is the best way? If not, how I can do this?</p>
  
  <p>I have the follow code</p>
  
  <pre><code>if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
      // PROBABLY AJAX REQUEST
  }
  </code></pre>
  
  <p>My question is, how I can verify <code>php://input</code> exists and are not empty? I think the follow code do the work, but need to know if this is a correct way:</p>
  
  <pre><code>if(file_get_contents("php://input") == '') {
      // HAVE NOT POSTED
  } else {
      // POSTED
  }
  </code></pre>