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
post.php
 <form method="post" action="post.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
get.php
 <form method="get" action="get.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 =