title: angularJs POST data in $_POST for php
body: <p>I am doing a post request to a php script form my AngularJS app. I have gotten it working by looking up answers online but I would like to get the data in my php script in the <code>$_POST['jwt']</code> variable.</p>
  
  <p>Here is my AngularJS code:</p>
  
  <pre><code>var dataReq = {
  method: 'POST',
  url: 'http://localhost/PHP/dataSender.php',
  headers: {
   'Content-Type': 'application/x-www-form-urlencoded'
   },
   data: { jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9' }
  }
  $http(dataReq).success(function(response,data) {
    console.log(response);
  });
  </code></pre>
  
  <p>In my PHP I have this :</p>
  
  <pre><code>$postdata = file_get_contents("php://input");
  $request = json_decode($postdata);
  @$jwt = $request-&gt;jwt;
  echo $jwt;
  </code></pre>
  
  <p>And it is working but if I change the header in my angular request to </p>
  
  <pre><code>'Content-Type': 'application/json'
  </code></pre>
  
  <p>I get the CORS error.</p>
  
  <p>Is there a way I can get the values in <code>$_POST</code> variable because I have never worked with this <code>file_get_contents("php://input");</code></p>
  
  <p>How can I check for the values is set or not
  in <code>$_POST</code> I would do something like this:</p>
  
  <pre><code>if(isset($_POST["jwt"]) &amp;&amp; !empty($_POST["jwt"]))
   {
    echo $_POST["jwt"];
    }
  </code></pre>
  
  <p>How can I do the same test in this <code>file_get_contents("php://input");</code></p>