PHP Get and Post Methods | Browser Role

PHP Get and Post Methods

PHP Get and Post Methods

1. GET Method:

This is the built-in PHP super global array variable that is used to get values submitted via HTTP GET method.

Data in GET method is sent as URL parameters that are usually strings of name and value pairs separated by ampersands (&).

URL with GET data looks like this:

http://msbte.cwipedia.in/dataread.php?name=ram&rollno=20.

The name and age in the URL are the GET parameters; ram and 20 are the value of those parameters.

More than one parameter=value can be embedded in the URL by concatenating with ampersands (&).

Only simple text data can only be sent through GET method.

Sensitive information such as the username and password can't be sent through GET method as it will be visible in the query string and it can store in browser memory as visited page


Length of the URL is limited as it assigns data to a server environment variable

Advantages of using the GET Method :

Since the data sent by the GET method are displayed in the URL, it is possible to bookmark the page with Specific query string values.

GET requests can be cached and GET requests to remain in the browser history.

GET requests can be bookmarked.


Disadvantages of using the GET Method

The GET method is not suitable for passing sensitive information such as the username and password because these are fully visible in the URL query string as well as potentially stored in the client browser memory as a visited page.

Because the GET method assigns data to a server environment variable, the length of the URL is limited. So, there is a limitation for the total data to be sent.


Example:
<!DOCTYPE html>
<html>
<head>
 <title>cwipedia.in</title>
</head>
<body>
<form method="get" action=" ">
 Name:<input type="text" name="name">
 Address:<input type="text" name="add">
 <input type="submit" name="Save" value="Save">
</form>
<?php
echo "Name:-",$_GET['name']," Address:-",$_GET['add'];
?>
</body>
</html>
Output:

2. POST Method:

This is the built-in PHP super global array variable that is used to get values submitted via the HTTP POST method.

Data in POST method is sent to the server in the form of a package in a separate communication with the processing script.

User entered Information is never visible in the URL query string as it is visible in GET.

The POST method can be used to send a much large amount of data and text data as well as binary data (uploading a file).


Data sent by the POST method is not visible in the URL, so it is not possible to bookmark the page with a specific query.

Super global variable $_POST is used to access all the information sent through an HTML form Using the post method.

A good example of using post method is when submitting login details to the server.

Advantages of using POST Method

It is more secure than GET because user-entered Information is never visible in the URL query string or in the server logs.

There is a much larger limit on the amount of data that can be passed and one can send text data as well as binary data (uploading a file) using POST.

Disadvantages of using the POST Method

Since the data sent by the POST method is not visible in the URL, so it is not possible to bookmark the page with a specific query.

POST requests are never cached.

POST requests do not remain in the browser history,

Example:
<!DOCTYPE html>
<html>
<head>
 <title>cwipedia.in</title>
</head>
<body>
<form method="POST" action=" ">
 Name:<input type="text" name="name">
 Known As:<input type="text" name="add">
 <input type="submit" name="Save" value="Save">
</form>
<?php
echo "Name:-",$_POST['name']," Known as:-",$_POST['add'];
?>
</body>
</html>
Output:



Comments