PHP Simple example of using get and post
In this tutorial we are going to talk about the difference of POST and GET method and show you with simple examples how you can use them for sending data from forms.
First of lets start with the GET method. The GET method is primarily used for passing along data that you would need on other pages through the URL, and it’s considered a less secured way then the POST method.
EXAMPLE:
Form1.html
<html>
<head> <title> Example </title> </head>
<body>
<form method=”get” action=”handler.php”>
Enter your first name <input type="text" name="fname" />
Enter your last name <input type="text" name="lname" />
<input type="submit" />
</form>
</body>
</html>
Handler.php
<html> <head> <title> Handler </title> </head> <body> <?php $fname = $_GET["fname"]; $lname = $_GET["lname"]; echo "Hello " . $fname . " " . $lname . "thanks for visiting my webpage!"; ?> </body> </html>
Now that we covered the basics of the GET method, lets talk about POST. With POST you can pass along information like passwords, usernames, PIN codes and other credit card information. This method doesn’t show any of the form tags in the URL. The form.html would be similar and what you do with the information got from the POST method should be know only by you.



