PHP Get and Post Method

You are currently viewing PHP Get and Post Method

PHP Get and Post Method

Get method : The GET method sends the data as part of the URL, which means that the data is visible in the address bar of the browser. This method is useful for sending small amounts of data, such as search queries.
In the following HTML code we have created a form with text field as Username and Phone Number. we have also included a PHP file getmethod.php where our data would be sent after we click the submit button.

index.html

				
					<!DOCTYPE html>
<html>
<body data-rsssl=1>
<form action="getmethod.php" method="GET">
Username: <input type="text" name="uname" /> <br>
Phone: <input type="text" name="phone" /> <br>
<input type="submit" />
</form>
</body>
</html>

				
			

In the following PHP code using the GET method we have displayed the Username and Phone Number.

getmethod.php

				
					<!DOCTYPE html>
<html>
<body data-rsssl=1>
Welcome
<?php echo $_GET["uname"]; ?> </br>
Your Phone nummber is:
 <?php echo $_GET["phone"]; ?>
</body>

</html>

				
			

Output: Data passed in GET method is clearly visible in the address bar, which can compromise the security.

php get method

Post method : The POST method sends the data in the HTTP request body, which means that it is not visible in the address bar. This method is useful for sending large amounts of data, such as form submissions.
In the following HTML code we have created a form with text field as Username and Phone Number. we have also included a PHP file postmethod.php, where our data would be sent after we click the submit button.

index.html

				
					<!DOCTYPE html>
<html>

<body data-rsssl=1>
<form action="postmethod.php" method="post">
Username: <input type="text" name="uname" /> <br>
Phone Number: <input type="text" name="phone" /> <br>

<input type="submit" />
</form>
</body>

</html>

				
			

In the following PHP code using the POST method we have displayed the Username and Phone.
postmethod.php

				
					
<html>

<body data-rsssl=1>
Welcome
<?php echo $_POST["uname"]; ?> </br>
Your Phone number  is:
<?php echo $_POST["phone"]; ?>
</body>

</html>

				
			

Output: Data passed in POST method is not shown in the address bar, which maintains the security.

php post method

Leave a Reply