title: How to post data using curl and get reponse based on posted data
body: <p>Here is my code to <code>POST</code> data:</p>
  
  <pre><code>&lt;?php
  $data = array("account" =&gt; "1234", "dob" =&gt; "30051987", "site" =&gt; "mytestsite.com");
  $data_string = json_encode($data);
  
  $url = 'http://mydomain.com/curl.php';
  
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Content-Type: application/json',
      'Content-Length: ' . strlen($data_string))
  );
  $result = curl_exec($ch);
  curl_close($ch);
  $json_result = json_decode($result, true);
  ?&gt;
  
  &lt;p&gt;Your confirmation number is: &lt;strong&gt;&lt;?php echo $json_result['ConfirmationCode']; ?&gt;&lt;/strong&gt;&lt;/p&gt;
  </code></pre>
  
  <p>Whereas on domain/server <strong>curl.php</strong> file code as under:</p>
  
  <pre><code>&lt;?php
  // header 
  header("content-type: application/json");
  
  if($_POST):
      echo json_encode(array('ConfirmationCode' =&gt; 'somecode'));
  else:
      echo json_encode(array('ConfirmationCode' =&gt; 'none'));
  endif;
  ?&gt;
  </code></pre>
  
  <p>But it always return <code>'none'</code>. Am I missing something?</p>