Retrieving json data

Recommend this page to a friend!

      PHP Request Parameter Options  >  All threads  >  Retrieving json data  >  (Un) Subscribe thread alerts  
Subject:Retrieving json data
Summary:Reading from php://input
Messages:3
Author:Christian Vigh
Date:2015-11-11 08:48:16
 

 


  1. Retrieving json data   Reply   Report abuse  
Picture of Christian Vigh Christian Vigh - 2015-11-11 08:48:16
Hi Vallo,

I have had a look at your package with great interest and noticed something I was totally unaware of : retrieving json data from an http request.

I saw that you used the file_get_contents() function on php://input and this seems weird (and also really new) to me : what part of an http request does it allow to retrieve ? does it work with form data including attached files ? and in fact, could one use this trick to process any kind of data, not only json ?

Many thanks for your help,
Christian.

  2. Re: Retrieving json data   Reply   Report abuse  
Picture of Vallo Reima Vallo Reima - 2015-11-11 11:36:57 - In reply to message 1 from Christian Vigh
Hi Christian,

The file_get_contents('php://input'); is a convenient method to read raw data from the request body. I use this mainly to process the AJAX JSON requests. The form data is better to send/retrieve via $_POST.

It all depends on what data is sent and how. More information:
php.net/manual/en/wrappers.php.php

Best regards,
Vallo


  3. Re: Retrieving json data   Reply   Report abuse  
Picture of Christian Vigh Christian Vigh - 2015-11-11 12:01:59 - In reply to message 2 from Vallo Reima
Hello Vallo,

thanks for the explanation and for the link ! in fact, so far I only considered php://stdin with regards to CLI mode so I somewhat skipped the very interesting paragraph about POST requests in the PHP documentation.

Suddenly I have a myriad of new ideas regarding this feature so... thanks for the approach you have taken for this package and for the knowledge it brings to the developers !

Christian.

 

For more information send a message to info at phpclasses dot org.