MrBool
You must be logged in to give feedback. Click here to login
[Close]

You must be logged to download.

Click here to login

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Difference between POST and GET methods in PHP Programming

In this article you can learn about the use of POST and GET methods in PHP programming. And we also discuss the security leakage of GET method in PHP programming.

[close]

You didn't like the quality of this content?

Would you like to comment what you didn't like?

Before we start this article in details, let’s create a simple webpage and use POST method first of all. The use of POST method is simple and we will also use $_POST[] to get data from the forms.

Listing 1: UserArea.html

<!DOCTYPE HTML>
<html>
<head><title>Difference between Post and Get method in PHP</title></head>
<body>
<p><h1>Sign-In</h1></p>
<table>
<form action="data.php" method="POST">
<tr><td>User</td><td> <input type="text" name="ID"></td></tr>
<tr><td>Password <t/d><td><input type="password" name="pass"></td></tr>
<tr><td><input type="submit" value="LOG-IN"></td></tr>
</form>
</table>
</body>
</html>
Output on browser of form with getting data from the user

Figure 1: Output on browser of form with getting data from the user.

Description of UserArea.html:

In listing 1, the form is very easy to understand. But the main thing is to understand the action() and method() which is used inside the form tag. The action() function is used to send form data to the data.php, which is a .php extension file. And in method() we used POST. It means that it will help the method() to send data to the data.php. And the data will be fully secure and hidden from the other people. Now a days mostly web developers and web application programmers are using POST methods. Because it is secure and it is not a part of URL that is HTTP.

Listing 2: data.php

<?php
//learning $_POST[] variable
$user = $_POST["ID"];
echo"<h1> Welcom Mr.".$user."</h1>";
?>

Description of data.php:

In data.php file there is a simple programming. In which we used $_POST[‘ID’], its mean that it will get the data from the form where we used POST method. And it will assign it to a variable which we by self-declared it. And then we used the echo object to output the data on the browser, as you can see it in Figure 2. As you can see in Listing 2, it is easy to use the $_POST[] to get data. And don’t worry about word “ID” inside the $_POST[] it is the name of input take which we used in form tag. We commonly use these methods in PHP form validation. The easiest way is to assign the data of $_POST[] to any declared variable. Then use that variable in the whole PHP program, as you can see it in Listing 2 I used it.

Using POST method in UserArea.html

Figure 2: Using POST method in UserArea.html

Result:

As you can see the result, when we used the POST method inside the form tag. So we get the result which is in Figure 2. And if we check the URL, so its look normal, there is no any security leakage.

Let’s we use the GET method in the same webpage.

Listing 3: UserArea.html

<!DOCTYPE HTML>
<html>
<head><title>PHP Variables</title></head>
<body>
 <p><h1>Sign-In</h1></p>
<table>
<form action="data.php" method="POST">
<tr><td>User</td><td> <input type="text" name="ID"></td></tr>
<tr><td>Password <t/d><td><input type="password" name="pass"></td></tr>
<tr><td><input type="submit" value="LOG-IN"></td></tr>
</form>
</table>
</body>
</html>

Description of Listing 3:

If we check the Listing 3, so every line is looking same as we saw in Listing 1. But there is a change inside the form tag that is we used GET method instead of POST method.

Listing 4: data.php

<?php
//learning $_GET[] variable
$user = $_GET["ID"];
echo"<h1> Welcom Mr.".$user."</h1>";
?>

Description of Listing 4:

If we check the Listing 4, so you will also see a single change in it. That is we used $_GET[‘ID’] variable to get the data from the UserArea.html webpage. And it will do same thing as we saw in Listing 2.

Using GET method in UserArea.html

Figure 3:Using GET method in UserArea.html

After using the GET method so what we see on the URL. We get our id and password over there which are fully correct. But it is not a good thing for a user if he/she wants to be login to their profiles on internet. The hackers will hack their profiles. And they will get their all private and secret data. Check the URL: http://localhost/data.php?ID=mrbool123&pass=mrbool123. The ID and Password is same which we insert to get login in our profile.

Result:

If someone want to use the GET method so they are doing a big mistake. Because it is not secure and as we know there is a technique of hacking IDs that is PHISHING technique. It is a better idea if we use POST in these kind of webpages.

More Details about GET and POST methods in PHP:

When we use GET in webpages, so it’s mean that we are going to append that data in the designated URL. As you can see the Figure 3 for more details. And you should know that the POST is not the part of the URL.

And the good advantage of using GET is to bookmark any URL. As many search engines are using it. As we know the GET is a part of URL so it will remain in the browser history. And the POST data will not remain in the browser history. There is also another advantage of using POST method that is we can use multipart/form-data for encoding of binary data.

We can see many examples of GET in our daily life when we are surfing internet. For example http://search.yahoo.com/bin/search?seal=lishes there are many examples like this in which we can get data easily. There is another method in PHP programming which we can use it instead of POST and GET that is REQUEST.

$_REQUEST[] is an alternative method of $_POST[] and $_GET[]:

Commonly we call the $_REQUEST is an global variable which is can be execute form any part of the PHP program. There will no need to declare a global variable when we are using $_REQUEST. If we are using POST method to send data or GET method to send data from the form to PHP programmed webpage. So we can receive them or get them by using of $_REQUEST[]. So let’s we try this variable to receive data in PHP webpage.

Listing 5: Using POST method to send data from form

<!DOCTYPE HTML>
<html>
<head><title>PHP Variables</title></head>
<body>
<p><h1>Sign-In Form</h1></p>
<table>
<form action="data.php" method="POST">
<tr><td>User</td><td> <input type="text" name="ID"></td></tr>
<tr><td>Password <t/d><td><input type="password" name="pass"></td></tr>
<tr><td><input type="submit" value="LOG-IN"></td></tr>
</form>
</table>
</body>
</html>

Listing 6: Using $_REQUEST to receive data in PHP webpage

<?php
//learning $_REQUEST[] varialbe
$user = $_REQUEST["ID"];
echo"<h1> Welcom Mr.".$user."</h1>";
?>

Description of Listing 5 and 6:

If we check the coding of Listing 5, so there we used the method as POST and its mean that it is not a part of URL and HTTP. Our data will be secure from the hackers, and it will be receive securely on PHP webpage as you can see the coding of PHP webpage in Listing 6. The output of this will remain same as we saw in Figure 2. Let’s we change the method from POST to GET and check what happen?

Listing 7: Using GET method to send data from form

<!DOCTYPE HTML>
<html>
<head><title>PHP Variables</title></head>
<body>
<p><h1>Sign-In</h1></p>
<table>
<form action="data.php" method="GET">
<tr><td>User</td><td> <input type="text" name="ID"></td></tr>
<tr><td>Password <t/d><td><input type="password" name="pass"></td></tr>
<tr><td><input type="submit" value="LOG-IN"></td></tr>
</form>
</table></body>
</html>

Description of Listing 7:

If we see the coding of Listing 7, the html based webpage. So we just replace POST with GET. And will not do any changing in the PHP webpage. We will use the same PHP webpage as you can see the coding in Listing 6. And the output will same as we saw in Figure 3. Follow the Listings numbers from 5 to 7. Then you will able to understand the features of $_REQUEST in PHP webpage programming or development.

RESULT:

After discussing the $_REQUEST the global variable. We now able to know that we can use it instead of $_POST and $_GET. And the output or we can say that the processing functions will remain same or constant. And the predefined $_REQUEST variable also contains the data of $_COOKIE. Which is not discussed in this article because it is fully change from our topic.

Conclusion:

From this article we learnt that what the difference of POST and GET methods is when we use them in form to send data to another webpage. And also we discuss the $_REQUEST to use it instead of $_POST and $_GET. I hope your all arising questions will be solved by reading of this article. If you have any kind of query related to this article please do a comment without any hesitating.



Studing Computer Science and have knowledge in C/C++, Java, VB.net, C#, Assembly Programming, MFC, HTML, XML, JAVASCRIPT, AJAX, JQUERY, PHP, MYSQL, ORACLE

What did you think of this post?

Did you like the post?

Help us to keep publishing good contents like this.

SUPPORT US

funded

remaining

[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually � in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits � in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login