HTTP PUT, DELETE and I / O Streams with PHP

Is there a way to access data that was sent using the HTTP PUT method, except for $putdata = fopen("php://input", "r"); ?

I have never worked with the PUT and DELETE methods, and $putdata = fopen("php://input", "r"); seems a bit sketchy. Will it work everywhere, do you need a specific /php.ini server configuration?

I know that I can get the request method from $_SERVER['REQUEST_METHOD'];

But will the data be in $_REQUEST , if so, what does php://input mean? And how do I access data that was sent via DELETE ?

+4
source share
1 answer

No, you will need to manually parse the request. $_REQUEST contains only data coming from GET and POST requests; for everything else you are on your own.

If your HTTP request has Content-Type: application/x-www-form-urlencoded , you can easily parse_str it back into an array of variables with parse_str as follows:

 parse_str(file_get_contents('php://input'), $vars); print_r($vars); 

This type of content can be used with any HTTP method, there is no standard restriction.

+3
source

All Articles