Wednesday, July 22, 2009

HTTP POST Method: Finding the data on the receiving end

This is regarding FINDING the POSTed data with a PHP script. Where is it? Why do I keep coming up with NULL values when I look where it is supposed to be? Well, it depends on how the data was posted, and if some other site is posting the data you really don't know which method they will use. Here are the first three places to look:

print_r($_POST);

if(!isset($HTTP_RAW_POST_DATA)) $rawpost = file_get_contents( 'php://input' );

echo $GLOBALS['HTTP_RAW_POST_DATA'];

There are more places to hunt, but so far these three have worked for me.

PS With the second method above, when receiving XML, you end up with \" for every ", which can mess you up. Try following up with

$cleanpost = str_replace( '\"', '"', $rawpost );

No comments:

Post a Comment