Setup Menus in Admin Panel

  • No products in the cart.

  • LOGIN

PHP GET and POST method

Methods of sending information to the web server:

While dealing with the forms,information can be transferred with the same page or different page using the two methods i.e

1.GET method

2.POST method

Now we will disscuss about PHP methods in details.

1.GET METHOD:

In GET method the data is sent as URL parameters that are usually strings of name and value pairs.

They are separated by ampersands (&).

The below examples shows how the URL will look like;

http://www.phphelp.net/index.php?name=rajesh&[email protected]&contact=9999999999

Client Side:
The below example code is an HTML form with method=”get” .

<form action="#" method="get">
<input type="text" name="name" placeholder="Name"></input><br/>
<input type="text" name="email" placeholder="Email"></input><br/>
<input type="text" name="contact" placeholder="Mobile number"></input><br/>
<input type="submit" name="submit" value="Submit"></input>
</form>

Server Side:
The below example is a  PHP script where, $_GET is used to receive sent information at server end.

<?php
if( $_GET["name"] || $_GET["email"] || $_GET["contact"])
{
echo "Hello: ". $_GET['name']. "<br />";
echo "Email is: ". $_GET["email"]. "<br />";
echo "Mobile No. is: ". $_GET["contact"];
}
?>


The above information generated by GET method can be readable in address bar therefore, we never recommend to  use Get method for sending sensitive information to server.Instead use POST method for sending the sensitive information.

 

2.POST METHOD:

As we have already explained above, before sending information to server, it converts client’s information into a query string in URL.

Client Side:

The below code is an HTML form with method=”post”.

<form action=”#” method=”post”>
….
</form>

Server Side:

The below code has PHP script where, $_POST  is used to receive sent information at server site.

<?php
if( $_POST["name"] || $_POST["email"] || $_POST["contact"])
{
echo "Hello: ". $_POST['name']. "<br />";
echo "Email is: ". $_POST["email"]. "<br />";
echo "Mobile No. is: ". $_POST["contact"];
}
?>

The query generated by Post method never appears in address bar i.e. it is hidden for the user.
Therefore, we can use this method for sending sensitive information to server.

ASSIGNMENT : How will you get information sent via post method in PHP? MARKS : 10  DURATION : 1 week, 3 days

ASSIGNMENT : How will you get information sent via get method in PHP? MARKS : 10  DURATION : 1 week, 3 days

SEE ALL Add a note
YOU
Add your Comment
 

Advanced Course Search Widget

Popular Courses

Course Categories

© PHPhelp. 2002 - 2018 All rights reserved.
X