Saturday, 11 July 2015

PHP GET & POST

Difference between PHP GET and POST method?
  • Get display the form values entered in the URL of the address bar where as Post does not do.
  • Get is used to submitted a small amount of data whereas Post is used to submitted large amount of data.
  • Get is used to store less sensitive data on the other hand Post are used to store more sensitive data as compare to php get method.
  • Get method are good for information required for either bookmarking a particular item, or for assisting in search engine optimization and indexing items. php post method is good for standard forms used to submit one time data.
  • Example of Get method shown below:

<?phpif( $_GET[“username”] || $_GET[“email”] ){echo “Welcome “. $_GET[‘username’]. “<br />”;
echo “You are “. $_GET[‘email’].”;
exit();
}
?>
<html>
<body>
<form action=”<?php $_PHP_SELF ?>” method=”GET”>
UserName: <input type=”text” name=”username” />
Email: <input type=”text” name=”email” />
<input type=”submit” />
</form>
</body>
</html>
  • Example of Post method is shown below:


<?phpif( $_POST[“username”] || $_POST[“email”] ){echo “Welcome “. $_POST[user’name’]. “<br />”;
echo “You are “. $_POST[‘email’]. ;
exit();
}
?>
<html>
<body>
<form action=”<?php $_PHP_SELF ?>” method=”POST”>
Name: <input type=”text” name=”username” />
Age: <input type=”text” name=”email” />
<input type=”submit” />
</form>
</body>
</html>

No comments:

Post a Comment