2

I'm currently trying to implement a system that posts data as 'multipart/form-data' and I am receiving the data through php://input as follows:

[
   {
      "id":"595944535043",
      "companyProfileID":"",
      "accountID":"",
      "ownerID":"",
      "importID":"",
      "avatarUrl":"https://d2ojpxxtu63wzl.cloudfront.net/static/a9b1a30bbf8148445118d0d70ebd4a01_16edde90d640c6ee84a1874a4dbb3cdc816bc9e94ec6a23efc885e59947b28ab",
      "companyName":"",
      "title":"",
      "firstName":"Madison",
      "lastName":"Test",
      "street":"",
      "city":"",
      "country":"",
      "state":"",
      "zipcode":"",
      "emailAddress":"email@email.com",
      "website":"",
      "phoneNumber":"",
      "officePhoneNumber":"",
      "phoneNumberExtension":"",
      "mobilePhoneNumber":"",
      "faxNumber":"",
      "description":"",
      "campaignID":"",
      "crmLeadID":"",
      "crmOpportunityID":"",
      "crmAccountID":"",
      "crmContactID":"",
      "crmOwnerID":"",
      "crmThirdPartyID":"",
      "formGUID":"",
      "trackingID":"",
      "leadSource":"",
      "industry":"",
      "active":"1",
      "isQualified":"",
      "isContact":"1",
      "isCustomer":"0",
      "hasOpportunity":"0",
      "lastActivityDate":"2018-06-08 15:04:10",
      "updateTimestamp":"2018-06-17 09:25:39",
      "updateUserProfileID":"0",
      "createTimestamp":"2018-06-08 14:04:10",
      "createUserProfileID":"313407940",
      "leadStatus":"contact",
      "persona":"",
      "services_5addf517bd49b":""
   }
]

However when I try and access any of these details via $_POST it dosen't return anything. A quick check indicates that $_POST is in fact empty.

I've exhausted all options on this question php $_POST array empty upon form submission

And this one PHP some $_POST values missing but are present in php://input

Changed my max_input_vars to 10000, post_max_size is 1G. Tried JSON decode solutions, parsestr solutions, nothing.

So just wondering if there's anybody out there who can help?

Not a duplicated question as the data is nested. Different to previous problems on Stack overflow

Joe
  • 85
  • 8
  • First read about POST fields and POST body , then `$posted_data = json_decode(file_get_contents("php://input"));` – Metalik Jun 17 '18 at 09:36
  • I've tried both of these methods. A var_dump of `$posted_data` returns nothing – Joe Jun 17 '18 at 09:41
  • Can you add where the request should be coming from? I.e the code of the section of code that sends the request to PHP. – FluxCoder Jun 17 '18 at 09:46
  • `Not a duplicated question as the data is nested. Different to previous problems on Stack overflow` it is because you can't use JSON in `$_POST`, `$_POST` is a PHP pre-setup variable that uses the same stuff as `parse_str ` if it's in the stdin stream `php://input` the just read it parse it into a different var E.G `$json = json_decode(file_get_contents("php://input"));` then you can use it like `$json[0]->id` – Barkermn01 Jun 22 '18 at 14:00
  • Notice the extra square brackets that Sharpspring serves the data in, this means that previous questions on here weren't applicable to this problem. I haven't found any previous answers that use `$json[0]->id` – Joe Jul 15 '18 at 13:18

2 Answers2

1

Wow so I managed to figure it out.

I took the POST data that i got via php://input and created a JSON variable with the data. Then after some testing I tried to see if treating it like a nested array after performing the $posted_data = json_decode(file_get_contents("php://input"));.

So i called the data using the following:

$posted_data[0]->emailAddress

And that worked... hope this can help anyone in the future and save the amount of hours i've just wasted :)

Joe
  • 85
  • 8
0

Increase the postmaxsize variable in php.ini was set to higher than the amount of physical RAM in the machine also use M suffix instead MB

Bharat
  • 36
  • 4