PHP Simple example of using get and post

Feb 20, 2011 Author: aleksandar

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.


<head> <title> Example </title> </head>
 <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>


<head> <title> Handler </title> </head>
$fname = $_GET["fname"];
$lname = $_GET["lname"];
echo "Hello " . $fname . " " . $lname . "thanks for visiting my webpage!";

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.

views 1407015
  1. Add New Comment

July 9,2011 at 17:17:07
Hi Welcome....!!!!
February 26,2012 at 19:41:45
thanks,, i will come in again
October 13,2012 at 13:21:28
i m greately thankful to w3school. i learn more n more from this site only . the best for students.....
December 19,2012 at 18:01:47
dear the get method example is really fine !!! thanks a lot.
Sajid anwar
October 1,2013 at 22:16:41
very fine