• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

GET vs POST in PHP | easy example

GET vs POST in php

This post will explain the GET vs POST in PHP with examples in php. Communication between client and server is enabled by HTTP [HyperText Transfer Protocol] which works in request and response method. Here the client is the web browser and server is the application that hosts the website. The different types of HTTP requests used in PHP are GET vs POST in PHP.

GET vs POST in PHP

GET Method

GET method is the method used for web request that pass data through website URL. It sends all form data as encrypted data or as raw data appended to action URL as parameter string. The webpage and this parameters is separated with ? (Question mark) symbol. Multiple Parameters are passed through URL separated by & (and) symbol. Parameters like value1 and value2 are sent as request.

For example: http://www.websitename.com?key1=value1&key2=value2…….

Points to know about GET method are given as follows:

  • Allows the data from a specified resource
  • Data sent through this request is stored in web browser history.
  • It have length restrictions since it is passed by URL. For example: Internet Explorer allows 2000 characters to pass through the URL or something like that which is quite limited.
  • It can be bookmarked and cached.
  • Second request will not be accepted until response of the first request is received. So duplication of records can be avoided.
  • This method have security restrictions to pass sensitive data over this request.  By robots and crawlers, the GET may be used arbitrarily is one of the reason, which would not considered as a the  request  method with no side effects.
  • This method is more efficient than post method.

POST Method

POST method is the most common request method used in php where data sent to the server is stored in the body of the HTTP request. When compared to GET vs POST in PHP this method is a little safer than GET since security depends on the HTTP protocol.

Point to know about POST method:

  • Submits the data which was processed to a specified resource.
  • In POST method data sent are not cached or saved in browser history
  • Data request can’t be bookmarked.
  • The restriction of sending limiting data in GET request method is overcome by this POST method.
  • This POST method is the most reliable request method to send important data to the server. If you are the one to upload large volume of data to server or in need to upload various data type it is the most trusted method.
  • It is less efficient than get method.
  • Difficult to hack the data .

EXAMPLE:

Test.php have the following code: here user select values and submit form. Once submitted it passes the value to the request page through the URL.

<html>
<head></head>
<body>
<b> Search Your Query:</b><br>
<FORM action="request.php" method = "GET">
<input type="radio" name="key2" value="Value1" checked>Value 1
<input type="radio" name="key2" value="Value2">Value 2
<input type="text" name="key1" size="20" maxlength="120">
<input type="submit" value="Search"><br>
</FORM>
</body>
</html>

Selected values are submitted to the request.php with values in URL.

If the same code in test .php use POST method to send data

<html>
<head></head>
<body>
<b> Search Your Query:</b><br>
<FORM action="request.php" method = "GET">
<input type="radio" name="key2" value="Value1" checked>Value 1
<input type="radio" name="key2" value="Value2">Value 2
<input type="text" name="key1" size="20" maxlength="120">
<input type="submit" value="Search"><br>
</FORM>
</body>
</html>

Then, data passed to the server with body request,not in a explicit manner which ensures security in the communication process.

Comparisons: PROS and CONS

In POST method we can’t say that there are no side effects. Here repeating the query is often expected that results in creating two messages instead of one. Re submission of data will happen while refreshing the request page.

Beside keeping the URL relatively cleaner, POST method also lets you to send much more information (as URLs are limited in length, for all practical application purposes), and also allow you to send any type of data such as binary data, images and other files.(for example, for file upload using form, we can’t use GET — they have to use POST with a special content type/encoding option).

Difference in processing

Processing a submitted form data depends on the method (METHOD=”GET” or METHOD=”POST”) through which data is sent. Since different ways are used in encoding the data, different decoding mechanisms are used. In simple, changing the method will change the script that process the data submitted. For example, In CGI interface — in Get method, the script receives the data as query string. But in POST method, data from the form is passed as standard input stream (stdin) and the Content-length header gives the number of bytes to be read.

Obviously web servers will keep the log of entire URL in plain text in their access logs. Of course sending sensitive data like passwords and other information over GET is not a good idea. It is applicable irrespective of whether HTTP or HTTPS (HTTP over TLS/SSL)is used.

This is all about GET vs POST in PHP.

Other Projects to Try:

  1. TestPage
  2. Program for taking Student details and storing in a database using Servlets and JSP.
  3. E-Post Office mini project
  4. Communication between applet and servlet Java Code
  5. Online Chat System project in PHP

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy