PHP 5.6.30 Released


$HTTP_POST_VARS [deprecated]

(PHP 4 >= 4.1.0, PHP 5)

$_POST -- $HTTP_POST_VARS [deprecated]HTTP POST variables


An associative array of variables passed to the current script via the HTTP POST method.

$HTTP_POST_VARS contains the same initial information, but is not a superglobal. (Note that $HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)

Log delle modifiche

Versione Descrizione
4.1.0 Introduced $_POST that deprecated $HTTP_POST_VARS.


Example #1 $_POST example

echo 'Hello ' htmlspecialchars($_POST["name"]) . '!';

Assuming the user POSTed name=Hannes

Il precedente esempio visualizzerà qualcosa simile a:

Hello Hannes!



Questa è una variabile 'superglobale', o automaticamente global. Ciò semplicemente significa che è visibile in tutti gli ambiti in uno script. Non è necessario dichiararla come global $variable; per accedervi da funzioni o metodi.

add a note add a note

User Contributed Notes 11 notes

james dot ellis at gmail dot com
8 years ago
One feature of PHP's processing of POST and GET variables is that it automatically decodes indexed form variable names.

I've seem innumerable projects that jump through extra & un-needed processing hoops to decode variables when PHP does it all for you:

Example pseudo code:

Many web sites do this:

<form ....>
<input name="person_0_first_name" value="john" />
<input name="person_0_last_name" value="smith" />

<input name="person_1_first_name" value="jane" />
<input name="person_1_last_name" value="jones" />

When they could do this:

<form ....>
<input name="person[0][first_name]" value="john" />
<input name="person[0][last_name]" value="smith" />
<input name="person[1][first_name]" value="jane" />
<input name="person[1][last_name]" value="jones" />

With the first example you'd have to do string parsing / regexes to get the correct values out so they can be married with other data in your app... whereas with the second example.. you will end up with something like:
//will get you something like:
array (
0 => array('first_name'=>'john','last_name'=>'smith'),
1 => array('first_name'=>'jane','last_name'=>'jones'),

This is invaluable when you want to link various posted form data to other hashes on the server side, when you need to store posted data in separate "compartment" arrays or when you want to link your POSTed data into different record handlers in various Frameworks.

Remember also that using [] as in index will cause a sequential numeric array to be created once the data is posted, so sometimes it's better to define your indexes explicitly.
darren_wheatley at hotmail dot com
1 year ago
I know it's a pretty basic thing but I had issues trying to access the $_POST variable on a form submission from my HTML page. It took me ages to work out and I couldn't find the help I needed in google. Hence this post.

Make sure your input items have the NAME attribute. The id attribute is not enough! The name attribute on your input controls is what $_POST uses to index the data and therefore show the results.
woodhavenbp at yahoo dot com
6 months ago
There's an earlier note here about correctly referencing elements in $_POST which is accurate.  $_POST is an associative array indexed by form element NAMES, not IDs.  One way to think of it is like this:  element "id=" is for CSS, while element "name=" is for PHP.  If you are referring to your element ID in the POST array, it won't work.  You must assign a name attribute to your element to reference it correctly in the POST array.  These two attributes can be the same for simplicity, i.e.,
<input type="text" id="txtForm" name="txtForm">...</input>
2 years ago
Note that $_POST is NOT set for all HTTP POST operations,  but only for specific types of POST operations.  I have not been able to find documentation, but here's what I've found so far.

$_POST _is_ set for:

Content-Type: application/x-www-form-urlencoded

In other words,  for standard web forms.

$_POST is NOT set for:


A type used for a generic HTTP POST operation.
alexiskarad at gmail dot com
11 days ago
Something interesting which might help someone else:
If your input field in HTML is "disabled", even if it contains text, $_POST will not return/contain any value.
As an alternative, you can use "readonly" in your input field.
paul at youngish dot homelinux^org
8 years ago
For a page with multiple forms here is one way of processing the different POST values that you may receive.  This code is good for when you have distinct forms on a page.  Adding another form only requires an extra entry in the array and switch statements.


if (!empty($_POST))
// Array of post values for each different form on your page.
$postNameArr = array('F1_Submit', 'F2_Submit', 'F3_Submit');       

// Find all of the post identifiers within $_POST
$postIdentifierArr = array();
    foreach (
$postNameArr as $postName)
        if (
array_key_exists($postName, $_POST))
$postIdentifierArr[] = $postName;

// Only one form should be submitted at a time so we should have one
    // post identifier.  The die statements here are pretty harsh you may consider
    // a warning rather than this.
if (count($postIdentifierArr) != 1)
count($postIdentifierArr) < 1 or
"\$_POST contained more than one post identifier: " .
implode(" ", $postIdentifierArr));

// We have not died yet so we must have less than one.
die("\$_POST did not contain a known post identifier.");
    switch (
"Perform actual code for F1_Submit.";

"Perform actual code for F2_Submit.";
"Perform actual code for F3_Submit.";
// $_POST is empty.
"Perform code for page without POST data. ";
perdondiego at mailinator dot com
5 years ago
In response to "php dot net at bigbadaboom dot net", adding the value attr to the image submit button may not work in older browser (Opera 9.x for example).

A better solution would be to add a hidden input (<input name="hidden" .... /> in the form to handle both cases: when we have a submit button or an image button for submitting
php dot net at bigbadaboom dot net
8 years ago
Make sure your submit buttons (ie. <input type="submit"> etc) have a 'value' attribute.  If they don't, the value won't appear in $_POST and so isset($_POST["submit"]) won't work either.


<input type="submit" name="submit">

isset($_POST["submit"]) returns false

<input type="submit" name="submit" value="Next">

isset($_POST["submit"]) returns true.

This might seem obvious for text buttons since they need a label anyway.  However, if you are using image buttons, it might not occur to you that you need to set a value attribute as well.  For example, the value attribute is required in the following element if you want to be able to detect it in your script.

<input type="image" name="submit" src="next.gif" value="Next">
paul dot chubb at abs dot gov dot au
8 years ago
Nasty bug in IE6, Apache2 and mod_auth_sspi. Essentially if the user presses the submit button too quickly, $_POST (and the equivalents) comes back empty. The workaround is to set Apache's KeepAliveTimeout to 1. This would mean that the user would need to push submit within a second to trigger the issue.
yesk13 at gmail dot com
6 years ago
you may have multidimensional array in form inputs

HTML Example:

<input name="data[User][firstname]" type="text" />
<input name="data[User][lastname]" type="text" />

Inside php script
after submit you can access the individual element like so:

$firstname = $_POST['data']['User']['firstname'];
7 years ago
# This will convert $_POST into a query string

= "";
if (
$_POST) {
$kv = array();
  foreach (
$_POST as $key => $value) {
$kv[] = "$key=$value";
$query_string = join("&", $kv);
else {
$query_string = $_SERVER['QUERY_STRING'];
To Top