Forum Moderators: open

Message Too Old, No Replies

POST information received from forms

can PHP access it without names?

         

david752

9:51 pm on Apr 5, 2002 (gmt 0)

10+ Year Member



The $_POST variable can be used in PHP to get a specific
field of a form sent using the POST method, by name:

$_POST["name"]

This is an associative array. A direct array reference
such as $_POST[0] always returns an empty string.

Is there any way to get a raw array of POST fields that
can be scanned without knowing their names beforehand,
just as GET fields can be scanned?

David

toadhall

5:27 am on Apr 6, 2002 (gmt 0)

10+ Year Member



David,
This is a user entry from the online PHP manual (search "predefined variables").
$GLOBALS["HTTP_RAW_POST_DATA"] contains the raw POSTed data from a request. Also available (obviously) as $HTTP_RAW_POST_DATA in the global scope.

david752

10:07 pm on Apr 6, 2002 (gmt 0)

10+ Year Member



This global variable is not always supported. My Apache does not support it.

However, the following code is also from the PHP Manual and seems to answer the question nicely.

echo "Values submitted via POST method:<br>";
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
echo "$key => $val<br>";
}