OVHcloud Community

Welcome to your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.

PHP cannot read incoming post data



I’ve created my own custom application in PHP and 2 hours ago sent it to my OVH hosting catalog. Ever since then it’s been nothing but problems.

My frontend sends to the backend data from a form in the following way with jQuery:

let formData = $('#token-form').serialize();
    var requestForTokens = $.ajax('file.php', {
      method: 'post',
      data: formData,
      contentType: "application/json",
      dataType: "json",
      encoding: "text/plain"

(there’s only one input named “access-token”)

On the backend I have the following code to verify incoming data:

  $postData = json_decode(file_get_contents('php://input'), true);
  $token = $postData['access-token'] ?: null;
  if (empty($token)) {
    $response['error_message']='Token cannot be empty';
//much more code later

Of course every request ends up with the empty token message.

Before I didn’t have the ‘contentType: “application/json”’ in my ajax request and I was just using “$_POST[‘access-token’]” to get contents of the incoming data, but the the server always responded with 400.

Please help. On my xampp localhost it worked perfectly, no problem. With OVH I constantly stumble upon every possible error.