tags:

views:

48

answers:

4

Hi everyone !

I've never used PHP but right now, I need to write a PHP file that displays in a log file the content of the body of a POST HTTP request.

I've read that you can access variables of the body via the _POST array. Unfortunately, it seems to be empty, although I'm pretty sure there is stuff in my HTTP request's body !

What should I use to be 100% sure of the content of my HTTP body ?

Thanks.

+1  A: 

Check this: http://www.daniweb.com/code/snippet216846.html

killer_PL
A: 

Maybe you misspelled it. The array's correct name $_POST.

Try this

<?php
var_dump($_POST);

and see what happens.

middus
+1  A: 

The global variable is $_POST, not _POST. Also it might be that you are sending the data via GET method, in which case you need to use the $_GET global variable.

If you want to check for either POST or GET method, you can use the global variable $_REQUEST. Sample code bellow:

<html>
<body>
<form method="POST" action="postdata.php">
<input type="text" name="mydata" />
<input type="submit">
</form>
</body>
</html>

file postdata.php:

<?php

$result = $_POST['mydata'];
echo $result;
Anax
Sorry for the late answer but I've convinced my client to use a GET method. But I'll keep all the answers here in mind for any future need ! Thanks everyone !
Dirty Henry
+3  A: 
$post_body = file_get_contents('php://input');

php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives. php://input is not available with enctype="multipart/form-data".

Note: php://input can only be read once.

(Source: http://php.net/wrappers.php)

salathe