Saturday, December 24, 2011

Post Method in PHP

Defination
POST is the preferred method of form submission today,particularly in non-idempotent usage (those that will result in permanent changes),such as adding information to a database. The form data set is included in the body of the form when it is forwarded to the processing agent.No visible change to the URL will result according to the different data submitted.


Example
<html>
<body>
<?php
//isset is a function that test a variable to see whether it has been assigned a value

if (isset($_POST["submit"])
{
  if( $_GET["name"] || $_GET["age"] )
  {
     echo "Welcome ". $_GET['name']. "<br />";
     echo "You Rollno is ". $_GET['rollno']. ";
     exit();
  }
}
?>

  <form action="<?php $_PHP_SELF ?>" method="GET">
  Name: <input type="text" name="name" />
  Age: <input type="text" name="rollno" />
  <input type="submit" />
  </form>
</body>
</html>

QUE: difference between get and post?

GET:

http://www.test.com/index.htm?name1=value1&name2=value2
  • The GET method produces a long string that appears in your server logs, in the browser's Location: box.
  • The GET method is restricted to send upto 1024 characters only.
  • Never use GET method if you have password or other sensitive information to be sent to the server.
  • GET can't be used to send binary data, like images or word documents, to the server.
  • The data sent by GET method can be accessed using QUERY_STRING environment variable.
  • The PHP provides $_GET associative array to access all the sent information using GET method.
POST:
  • 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 GET method.
    For GET methodClick to View

No comments:

Post a Comment