HTTP GET and POST Method in PHP
August 7, 2018
What is HTTP?
HTTP Stands for Hypertext Transfer Protocol (HTTP). That is Manipulate to enable communications between clients and servers. HTTP works as a request and response protocol between a client and server.
What is client and Server
There are two ways the browser client can send information to the web server. A web browser may be the client, and application on a computer that hosts a web site may be the server.
Browser submits an HTTP request to the server; then the server send a response to the client. The response contains status information about the request and may also contain the requested content.
HTTP have two request methods: GET and POST
1. GET – Requests data from a resource.
2. POST – Submits data to be processed to resource.
GET Method :
The GET method before sending any information , it converts values/data into a query string in URL known as Url Encoding. the encoded information are separated by the ? character.
Form code written in html:
Advantages and Disadvantages of Using the GET Method :
1. Since the data sent by the GET method are displayed in the URL, it is possible to bookmark the page with specific query string values.
2. The GET method is restricted to send upto 1024 characters only.
3. Never use GET method if you need to send sensitive information like password.
4. GET can’t be used to send binary data, like images or word documents, to the server.
5. the length of the URL is limited. So, there is a limitation for the total data to be sent.
6. PHP provides $_GET method to access all the sent information using GET method.
POST Method :
The POST method transmit information via HTTP headers. before sending information to server, it converts client’s information into a query string in URL.
<form action = "" method = "POST">
Name: <input type = "text" name = "name" placeholder="Your Name" /><br/>
Weight: <input type = "text" name = "email" placeholder="Your Email" /><br/>
<input type = "submit" />
Post Value get in php:
if( $_POST["name"] || $_POST["email"])
echo "Hello : ". $_POST['name']. "";
echo "Your Email is: ". $_POST["email"]. "";
Advantages and Disadvantages of Using the POST Method :
1. POST is more secure than GET because user entered information is never visible in the URL query string.
2. There is a much larger limit on the amount of data that can be passed and one can send text data as well as binary data using POST.
3.POST requests do not remain in the browser history.
4.The PHP provides $_POST associative array to access all the sent information using POST method.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face – we are here to solve your problems.