PHP GET and POST Methods



The GET and POST Methods

The html METHOD attribute used to send information to web server in different way. The ways are GET method and POST method.

The GET and POST method both used to send data to web server.


The GET Method

PHP GET method used to send data to web server with site url in address bar. The GET method the information appended to url after ? and send to web server .
The GET method never use when we have sensitive information like password.
The GET method only sent up-to 1024 characters append with url.
The GET method can not used to send image file or binary data to server.
We can use $_GET[] function to retrieve the information from address bar to on web page.

In previous php example, write Method=”GET” in form tags.

<FORM name=”form1″ action=”” method=”GET”>

GET method
PHP GET method for sent data.

In above GET method example image we can see the data in address bar after ?.

http://localhost/firstexample.php?name=&password=&Submit1=Login

Here the http://localhost/firstexample.php is out webpage url and name=”” and password=”” and Submit1=login.
If we use GET method for sent data then the all user can see the data at browser address bar.

Now in above example enter username=”meera” and password=”123″ then submit the button.

PHP GET method for sent data.
PHP GET method for sent data.

Now the address bar look like :

http://localhost/firstexample.php?name=meera&password=123&Submit1=Login

If we want to retrieve name and password values for further use we use $_GET[“element_name”] syntax.


The POST Method

The POST method is used to sent data to web server without appending in url at address bar.
The POST method send information with use of HTTP headers.
The POST has no size limit to sent data to web server.
When we work with sensitive data the POST method is better than GET method.
The POST method send binary data.
We can use $_POST[“element_name”] function to get data from a form.

In above example we use METHOD=”POST” like:

<FORM name=”form1″ action=”” method=”POST”>

POST Method in PHP
POST Method in PHP

Here, we enter username and password then click submit button. This time we can not seen any information at address bar. The POST method sent information without show in address bar.
When we use sensitive data then the POST method is secure method for send information.

If we want to retrieve name and password values for further use we use $_POST[“element_name”] syntax.

we will learn $_GET[] and $_POST[] functions in next php tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *