PHP Forms and User Input (Cont.)


PHP $_POST Variable
The $_POST variable is used to collect values from a form with method="post". The $_POST variable is an array of variable names and values sent by the HTTP POST method. Information sent with the POST method is invisible to others and has no limits on the amount of information to send.

HTML
11_1.php
 <form method="post" action="11_1.php">
  <textarea rows="2" cols="20" name="text">
   This is a test.
  </textarea>
  <input type="submit" name="act" value="Check"> 
 </form>
 <html><body>
 <?php
  echo  $_POST[text];
 ?>
 </body></html>
   
PHP $_GET Variable
The $_GET variable is used to collect values from a form with method="get". The $_GET variable is an array of variable names and values sent by the HTTP GET method. Information sent from a form with the GET method is visible to everyone (it is displayed in the browser’s address bar) and it has limits on the amount of information to send (max. 100 bytes). The predefined variable $_SERVER gives the server and execution environment information.

HTML
11_2.php
 <form method="get" action="11_2.php">
  $name = <input type="text" name="name"
    size="20" value="Ben Ten">
  <input type="hidden" name="SSN"
    value="123456789">
  <input type="submit" name="act"
    value="Check"> 
 </form>
<html><body> <?php echo "act = $_GET[act]"; echo "name = $_GET[name]"; echo "SSN = $_GET[SSN]"; echo "URL = $_SERVER[]"; ?> </body></html>
$name =