GET AND POST METHOD IN PHP

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.
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
Finally, it will produce the following result from POST Method: –

Brief Description of GET and POST Method

Hence, Both GET and POST is treated as $_GET and $_POST, its know as Superglobals which means that they are always accessible.

Finally, you can access these superglobals from any class, function or file without having to do anything special.

In PHP Both GET and POST create an array (e.g. array( key0 => value0, key1 => value1, key2 => value2, key3 => value3, …)).

wherein these array holds key and value pairs, where keys are the names of the form controls which are taken and values are the input data from the user.

In the GET Method, $_GET is an array of variables passed to the current script via the URL parameters.

when you send the Information from a form all variable names and values are displayed in the URL everyone can see.

GET also has limits to send the amount of information which limit is about 2000 characters, However, because the variables are displayed in the URL, it is possible to bookmark the page.

so, GET Method In PHP may be used for sending non-sensitive data.

$_POST is used to pass an array of variables to the current script via the HTTP POST method.

when we use the GET method then the values of the input fields are passed through the URL field of the web browser

But therefore,  in the case of POST method, all the values of the input field are passed in a hidden way.

The $_REQUEST variable

its contains the contents of both $_GET, $_POST, and $_COOKIE.

The PHP $_REQUEST variable can be used when we need to get the result from form data sent with both the GET and POST methods.

Finally, we get the result:-