PHP
downloads | documentation | faq | getting help | mailing lists | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

$_FILES> <$_GET
Last updated: Fri, 21 Nov 2008

view this page in

$_POST

$HTTP_POST_VARS [непрепоръчителна]

$_POST -- $HTTP_POST_VARS [непрепоръчителна]Променливи от тип HTTP POST

Описание

Асоциативен масив с променливи, предоставени на текущия скрипт посредством метода POST на HTTP.

$HTTP_POST_VARS съдържа същата начална информация, но не е свръхглобална. (Забележете, че $HTTP_POST_VARS и $_POST са две различни променливи и PHP ги третира като такива)

Дневник на промените

Версия Описание
4.1.0 Въведена е $_POST, за сметка на непрепоръчителната $HTTP_POST_VARS.

Примери

Example #1 Пример с $_POST

<?php
echo 'Здравей ' htmlspecialchars($_POST["name"]) . '!';
?>

Приемаме, че потребителят е предоставил name=Ники

Примерът по-горе ще изведе нещо подобно на:

Здравей Ники!

Бележки

Забележка: Това е 'свръхглобална' или автоматично глобална променлива. Това просто означава, че тя е налична във всички обхвати навсякъде из скрипта. Не е нобходимо да правите global $variable;, за да я достъпвате от тялото на функции и методи.



$_FILES> <$_GET
Last updated: Fri, 21 Nov 2008
 
add a note add a note User Contributed Notes
$_POST
jairhumberto at gmail dot com
31-Jul-2008 04:26
<?php

foreach($_POST as $k=>$v) $$k=$v;
//to use $_POST["example"] as $example

foreach($_GET as $k=>$v) $$k=$v;
//to use $_GET["example"] as $example

//or better:

foreach(${"_" . $_SERVER["REQUEST_METHOD"]} as $k=>$v) $$k=$v;
//to use $_GET["example"] or $_POST["example"] as $example

?>
php dot net at bigbadaboom dot net
15-Jul-2008 11:06
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.

Example:

<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
20-Jun-2008 02:49
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.
telconstar99 at hotnospampleasemail dot com
20-May-2008 03:49
<?
//If we submitted the form
if(isset($_POST['submitMe']))
{
     echo(
"Hello, " . $_POST['name'] . ", we submitted your form!");
}
//If we haven't submitted the form
else
{
?>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
    <input type="text" name="name"><br>
    <input type="submit" value="submit" name="submitMe">
    </form>
<?
}
?>

$_FILES> <$_GET
Last updated: Fri, 21 Nov 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites