This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
Receive JSON POST with PHP
(12 answers)
Closed 4 years ago.
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
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 :)
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
Related
This question already has answers here:
PHP "php://input" vs $_POST
(6 answers)
Closed 6 years ago.
I want know,from where should I provide username, password credential topher's code... I know it is some what silly question. I am not getting
$raw_post_data = file_get_contents('php://input');
how exactly works
Please help me...
Thanks in advance.. :)
Thanks for asking this. I learned something new today.
This was answered in another post. You are actually doing the same as reading $HTTP_RAW_POST_DATA (wich is deprecated).
Usually when just submitting a basic form you want to read $_POST to get an array of elements php already splitted neatly for you:
$_POST = array(
"key1" => "value1",
"key2" => "value2",);
But when you actually need key1=value1&key2=value2 you want to get the "raw post data". Thats what file_get_contents('php://input'); does.
file_gets_content is usually intended to read a file (local file or url).
This question already has answers here:
Parsing JSON with PHP
(6 answers)
Closed 7 years ago.
I know this one has been asked loads of times, so mods please do not close this off as no past answers have worked and I have searched already! So I'm using the HaveIBeenPwned API which outputs what is apparently JSON like so:
[
{
"Title":"000webhost"
,"Name":"000webhost"
,"Domain":"000webhost.com"
,"BreachDate":"2015-03-01"
,"AddedDate":"2015-10-26T23:35:45Z"
,"PwnCount":12345678
,"Description":"In approximately March 2015, the free web hosting provider 000webhost suffered a major data breach that exposed over 13 million customer records. The data was sold and traded before 000webhost was alerted in October. The breach included names, email addresses and plain text passwords."
,"DataClasses":[
"Email addresses"
,"IP addresses"
,"Names"
,"Passwords"
]
,"IsVerified":true
,"IsSensitive":false
,"LogoType":"png"
}
]
That is the output if I use the following:
echo $output;
json_decode($output) doesn't work. Using a foreach($output as $key) doesn't work, it says invalid argument if I use that. I have tried a normal for() loop and again no joy. What is wrong with this output? How do I get at the values within it? As you should be able to tell I'm using PHP.
Use json_decode($output, true);
Second parameter defines result data format - object (false, default) or associated array (true).
This question already has answers here:
Processing large JSON files in PHP
(7 answers)
Closed 8 years ago.
Some API is providing json file of 88MB. I need to store in some of its value in database.
$cURL="url here"
$str = file_get_contents($cURL);
$str = json_decode($str);
echo '<pre>';
print_r($str);
this code is not working because file size is too large. I need to convert that json file to a php array. I am not able to parse this file. Any help from anyone?
Quite complicated if the problem should be solved during the query. Caching the preliminary data on the filesystem then separate the values into chunks would be able to solve the issue.
This question already has answers here:
get json using php
(3 answers)
Closed 9 years ago.
When you're visiting this page:
https://www.googleapis.com/plus/v1/activities/z12gtjhq3qn2xxl2o224exwiqruvtda0i?key=AIzaSyAwnz3yjIcvsosfbudkzl9oogGrT21m6Ns
...I guess what is called an object, appears with a lot of information. But when I try to do a simple GET call and then print it, like so:
$tweets = $_GET['https://www.googleapis.com/plus/v1/activities/z12gtjhq3qn2xxl2o224exwiqruvtda0i?key=AIzaSyAwnz3yjIcvsosfbudkzl9oogGrT21m6Ns'];
print_r($tweets);
...It returns nothing... Why is that?
The $_GET super global is populated with the query string of the current request, it's not used to get stuff from the interwebs.
You're looking for file_get_contents():
$url = 'https://www.googleapis.com/plus/v1/activities/z12gtjhq3qn2xxl2o224exwiqruvtda0i?key=AIzaSyAwnz3yjIcvsosfbudkzl9oogGrT21m6Ns';
$tweets = file_get_contents($url);
print_r($tweets);
If that contains a JSON encoded response you need to additionally use json_decode() to use it.
Do you know how to use $_GET?
Check PHP documentation, you must have made a mistake, or you're using it the wrong way.
This question already has answers here:
PHP $_GET and $_POST undefined problem
(5 answers)
Closed 2 years ago.
I continue to get undefined printed out when I use print($_GET['user_username']); from the previous page. The URL of the page is page.php?user_username=Pete. Why is this happening?
$_GET manual says
An associative array of variables
passed to the current script via the
URL parameters.
First be sure that element exists
<?php
echo !isset($_GET["user_username"]) ? "undefined" : $_GET["user_username"];
?>
Or try var_dump against $_GET array to see if element with user_username key exists.
var_dump($_GET);
Is your request like this one?
http://www.mydomain.com/something.php?user_username=something
Try this code:
print_r($_GET);
You will get all the elements passed using get in array format. Then you can check it.. It also helps better in debugging many times.