Certify and Increase Opportunity.
Govt. Certified PHP-Developer
PHP – Variables From External Sources

HTML Forms (GET and POST)

When a form is submitted to a PHP script, the information from that form is automatically made available to the script. There are many ways to access this information, for example:

Example #1 A simple HTML form

<form action=”foo.php” method=”post”>
Name:  <input type=”text” name=”username” /><br />
Email: <input type=”text” name=”email” /><br />
<input type=”submit” name=”submit” value=”Submit me!” />

Depending on your particular setup and personal preferences, there are many ways to access data from your HTML forms. Some examples are:

Example #2 Accessing data from a simple POST HTML form
// Available since PHP 4.1.0

echo $_POST[‘username’];
echo $_REQUEST[‘username’];

import_request_variables(‘p’, ‘p_’);
echo $p_username;

// As of PHP 5.0.0, these long predefined variables can be
// disabled with the register_long_arrays directive.

echo $HTTP_POST_VARS[‘username’];

// Available if the PHP directive register_globals = on. As of
// PHP 4.2.0 the default value of register_globals = off.
// Using/relying on this method is not preferred.

echo $username;

Using a GET form is similar except you’ll use the appropriate GET predefined variable instead. GET also applies to the QUERY_STRING (the information after the ‘?’ in a URL). So, for example, http://www.example.com/test.php?id=3  contains GET data which is accessible with $_GET[‘id’]. See also $_REQUEST and import_request_variables().