Get PUT and DELETE data

REST is very popular as a web service technique and PHP (v5.1) has got great support for POST through the $_POST (and $_GET for that matter) but for PUT, DELETE and OPTIONS we have to do a little different.

To get the data from a PUT request we can use this technique:

if($_SERVER['REQUEST_METHOD'] == 'PUT') {  
    $data = file_get_contents('php://input');  
} 

This will put the data from the PUT request into the $data variable. If you want DELETE och OPTION just check for those request methods instead and use the same fetch method as above.

Comments are closed.