Skip to content


php: processing raw Post / Get Values

I just added a jquery plugin to call head requests, but because you are not doing a get or post request php won’t convert the values that are sent back to their form.
To get around this we have to use the php://input stream ( is that the right word?) which is handy for a lot of things.

$data = file_get_contents("php://input");
$lines = explode("&",$data);
foreach($lines as $line) {
    list($key,$value) = explode("=",$line,2);
    $_REQUEST[$key] = $value;
}

basically this grabs the data from the php://input and then splits it up into it’s component parts and then stores that within the $_REQUEST superglobal array.
Why $_REQUEST well we’re calling a head request and not a post or get request, so where else should it go.

The php://input is handy when doing stuff like xmlRPC or jsonRPC etc ..

Hopefully this will benefit someone out there

<edit>
Thanks to Mortal of #php on OFTC (irc) for pointing out the unlimited explode

Posted in PHP.

Tagged with , , , , , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.


Get Adobe Flash playerPlugin by wpburn.com wordpress themes