What is HTTP_RAW_POST_DATA?

Lecture



1) What is it?
$ HTTP_RAW_POST_DATA contains the raw (raw) POST data.
those. if we send the following dataset via POST:
(
[name] => Masha
[time] => 12-00
)

then the following line will be in $ HTTP_RAW_POST_DATA:
name=John&time=2pm

2) How can I reach another variable?
Three equal ways:
$ HTTP_RAW_POST_DATA
$ GLOBALS ['HTTP_RAW_POST_DATA']
file_get_contents ('php: // input')

3) The $ HTTP_RAW_POST_DATA variable is not available. What to do?
- in php.ini enable always_populate_raw_post_data = On, which will always allow to fill the $ HTTP_RAW_POST_DATA variable
- access data via file_get_contents ('php: // input'). This method does not depend on directives in php.ini.
- use any unidentified MIME data type (for example: $ HTTP_RAW_POST_DATA is not generated for: multipart / form-data and application / x-www-form-urlencoded types and works for application / octet-stream type)

4) Why is the $ _POST array empty, although the data is accurately transmitted?
Because this data could not be processed and they are simply located in $ HTTP_RAW_POST_DATA

5) What is: php: // input?
php: // input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php: // input instead of $ HTTP_RAW_POST_DATA, since this method does not depend on special php.ini directives. In addition, in cases where $ HTTP_RAW_POST_DATA is not populated by default, it is potentially less memory-intensive than activating the always_populate_raw_post_data directive. php: // input is not available with content type enctype = "multipart / form-data".

6) You can show by example what $ HTTP_RAW_POST_DATA is?

  We send via POST array:
 Array
 (
     [name] => Masha
     [time] => 12-00
 )
 We get: 

CONTENT_TYPE: application / octet-stream

$ _POST array:
Array
(
)


Variable $ HTTP_RAW_POST_DATA:
name = Masha & time = 12-00

File_get_contents ('php: // input') value:
name = Masha & time = 12-00

- >> We notice that the $ _POST array is empty, $ HTTP_RAW_POST_DATA is available << -

CONTENT_TYPE: application / x-www-form-urlencoded

$ _POST array:
Array
(
[name] => Masha
[time] => 12-00
)


Variable $ HTTP_RAW_POST_DATA:
Undefined variable: HTTP_RAW_POST_DATA

File_get_contents ('php: // input') value:
name = Masha & time = 12-00

- >> Data in $ _POST, and $ HTTP_RAW_POST_DATA is inaccessible << -


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Running server side scripts using PHP as an example (LAMP)

Terms: Running server side scripts using PHP as an example (LAMP)