Wednesday, 15 November 2017

Starting with POST Method in PHP

The POST Method
The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING.
  • The POST method does not have any restriction on data size to be sent.
  • The POST method can be used to send ASCII as well as binary data.
  • The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure.
  • The PHP provides $_POST associative array to access all the sent information using POST method.
Try out following example by putting the source code in script.
Post.php
<?php
   if( $_POST["name"] || $_POST["age"] ) 
{
      if (preg_match("/[^A-Za-z'-]/",$_POST['name'] ))
 {
         die ("invalid name and name should be alpha");
      }
      echo "Welcome ".$_POST['name']. "<br />";
      echo "You are ".$_POST['age']. " years old.";
      exit();
   }
?>
<html>
   <body>
      <form action = "<?php $_PHP_SELF ?>" method = "POST">
         Name: <input type = "text" name = "name" />
         Age: <input type = "text" name = "age" />
         <input type = "submit" name="submit" value="submit"/>
      </form>
   </body>
</html>

0 comments

Post a Comment