How to use GET and POST Method in PHP with Explanation?
GET and POST METHOD are used in PHP, the browser client can send information to the web server.
it encodes before the browser sends the information it using scheme so, due to it is called URL encoding.
therefore, In the schema different pairs are separated by the ampersand, name and value pairs are joined with equal signs
Here nonalphanumeric characters are replaced with a hexadecimal value
spaced are removed and replaced with the + character after the information is encoded it is sent to the server.
Difference Between the POST and GET Method
GET Method Transfers the information through HTTP head location and displays the data on URL address bar
The GET Method is unsecured
consequently, GET Method transfers the limited amount of data
From the GET Method cannot upload the file.
PHP POST Method transfers the information through document body.
You Know, POST Method is very highly secured.
In PHP, the POST Method can transfer a Large amount of data
POST Method able to upload the files
THE GET METHOD
from the GET Method, It always sends encoded user information appended to the page request.
GET Method in PHP produces a long string that which appears in your server logs, in the browser’s Location
It’s restricted to send up to 1024 characters only.
Never use GET method if you have sensitive information to be sent to the server and password or other.
GET Method can’t be used to send binary data, like word documents, images to the server.
we can be accessed The data sent by GET method using the QUERY_STRING environment variable.
using GET method, $_GET associative array to access all the sent information.
echo"Welcome ".$_GET['firstname']."<br />";
echo"you are ".$_GET['age']." years old.";
First Name:<input type="text"name="firstname"/>
Finally, it will produce the following result from GET Method: –
THE POST METHOD
The Best Thing is that POST method transfers information via HTTP headers. The information which sends is encoded as described in the case of GET method and put into a header so it is called QUERY_STRING.
The POST method does not restrict to send any size of data.
The POST method can be used to send binary data as well as ASCII.
The data sent by POST method goes through HTTP header, By using Secure HTTP you can make sure that your information is secure so security depends on HTTP protocol.
we can use POST method in PHP to provides the $_POST associative array to access all the sent information