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 $_POST['jwt']
variable.
Here is my AngularJS 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);
});
In my PHP I have this :
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
@$jwt = $request->jwt;
echo $jwt;
And it is working but if I change the header in my angular request to
'Content-Type': 'application/json'
I get the CORS error.
Is there a way I can get the values in $_POST
variable because I have never worked with this file_get_contents("php://input");
How can I check for the values is set or not
in $_POST
I would do something like this:
if(isset($_POST["jwt"]) && !empty($_POST["jwt"]))
{
echo $_POST["jwt"];
}
How can I do the same test in this file_get_contents("php://input");