Using php://input stream

Looking over someone’s code today, I found them using the php://input stream. Having known of this stream but never having used it, I decided it was about time to do something about it.

Below you will find a very simple example, which should explain in itself how to read the request body from the php://input stream.

<!DOCTYPE html>
        <form method="post">
            <input type="text" name="inputfield1" value="test1" /><br />
            <input type="text" name="inputfield2" value="test2" /><br />
            <input type="text" name="inputfield3" value="test3" /><br />
            <input type="text" name="inputfield4" value="test4" /><br />
            <input type="text" name="inputfield5" value="test5" /><br />
            <input type="submit" />
        <hr />
<?php   echo 'php://input<br />';
        $input = file_get_contents("php://input");
        parse_str($input, $input_arr);
        echo $input, '<br />';
        var_dump($input_arr); ?>