- What is PHP
- PHP Installation
- PHP with Wampserver
- Write PHP code
- Comment Code in PHP
- Echo and print
- PHP Variables
- PHP Variables Scope
- Arithmetic Operators
- Logical Operators
- Assignment Operators
- Comparison Operators
- String Operators
- PHP Conditional Statement
- IF - ELSE Statement
- IF - ELSEIF - ELSE Statement
- PHP Switch Statement
- PHP Loop Types
- PHP for loop
- PHP while loop
- PHP do-while loop
- PHP foreach loop
- PHP Constant
- PHP Magic Constants
- PHP Function
- PHP isset() Function
- PHP empty() Function
- PHP String Functions
- PHP with HTML Forms
- PHP GET and POST Methods
- Form ACTION attribute
- $_GET, $_POST, $_REQUEST
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”>
In above GET method example image we can see the data in address bar after ?.
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.
Now the address bar look like :
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”>
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.