$_GET method in PHP and its Disadvantage

In this article we going to see How to Use and Disadvantage of $_GET method in PHP. As GET is Super global variable in PHP.

First we going see how to submit any data using GET method in PHP.

Let Start point called the passing of data using in PHP

To submit data using GET method we going to use form.

Actually point is how we can collect submitted from user by using $_GET method PHP.

As the GET method creates an array (e.g. array( keyone => valueone, keytwo => valuetwo, keythree => valuethree, …)).

It holds key or value pairs, where these keys are the names of the form controls and values are the input data from the user.

One Important point about GET is treated as $_GET.

And it is a superglobal, which means that they are always accessible and also regardless of scope.

It also one of the important points is that we can easily access them from any function, class or file without having to do anything special.

Important point regarding $_GET is an array of variables passed to the current script via the URL parameters after submitting form data, if we use method to get.

Mostly get method is used for sending data called non-sensitive data.

Below is the example which contains an HTML form with two input fields, and a submit button.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>contains demo</title>
</head>
<body>
<form action="" method="get">
Name: <input type="text" name="name" value="<?php echo (isset($_GET["name"])?$_GET["name"]:''); ?>"><br/>
Email: <input type="text" name="email" value="<?php echo (isset($_GET["email"])?$_GET["email"]:''); ?>"><br/><br/>
<input type="submit"><br/>
</form>
<?php if(isset($_GET["name"])){ ?>
Welcome <?php echo $_GET["name"]; ?>!
Your email address is <?php echo $_GET["email"]; ?> 
<?php } ?>
</body>
</html>

OUTPUT:

Result Output
Result Output

Disadvantage of GET method in PHP :

If we use get method, in this case as know that visited addresses will be saved in the browser history.

So due to which it is possible for a user to send again the same variable data with the same value at another or one more time.

It could be risky if we send data via links to send important data to the server, such as users and passwords.

Imagine a link that looks like this:

URL LINK
URL LINK

This would create a serious security problem for every user.

For example, they access from a shared computer, since other users could visit the link from the browser history.

It enter where they should not so this main and major disadvantage of GET method sending data via link.

I hope you liked my this article. If you have any queries or any question regarding this, Feel free to comment on Me.

Leave a Comment