Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.7k views
in Technique[技术] by (71.8m points)

json - file_get_contents("php://input") showing null when var_dump

file_get_contents("php://input"); is not working.

$data=$_GET['json']; is working.

my url:

http://localhost/demo/plainjson.php?json={"order_number":"54321","id":"1102","status":3,"card_no":"1234"}

$data = file_get_contents("php://input");
$json = json_decode($data, true);
var_dump($json);// o/p->Null
print_r($json);// o/p-> nothing

echo $json[2];

how to echo or print the url json array or value using this need help. with explanation. thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

allow_url_include may not be set to true in your php.ini? This is common on some older shared hosting services

Refer to this Stack Overflow post for a potential fix.

Ahhh... The problem is that you arent POSTing anything. But rather sending it via query string so there is no body for the stream to retrieve. So as I understand it you cannot use a streams to get the data

See PHP.net Aritical

"php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST request"

Further more see this post


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...