How to get a specific data after post method?

In PHP or any other programming language, why in GET method variables and its values are passed through URL and in POST method not through URL?

  • What is the technique behind this?

  • Answer:

    GET requests can be cached (browser cache, history, bookmarked, shared and distributed) etc. Therefore, all the data passed in a GET request needs to be in the URL to be used as a unique cache key by the browsers and the edge caches. POST requests are typically used to upload files or update database records etc. The data associated with them is typically huge and sensitive and the actions impact the state of the backend. So if you put all POST data in the URL, there is a possibility that this URL will get shared or even indexed by a search engine crawler and will cause some irreversible damage to your server state. (This is a common accident that happens when people mistakenly use GET request where they need a POST instead). Therefore, POST data is passed via the request body and not in the URL.

Kiran Badam at Quora Visit the source

Was this solution helpful to you?

Other answers

You can think about it as GET being idempotent (returns a document -what browsers are meant to do - without any other side-effects), while POST is sending data to a server (what forms generally do). It's quite important to understand that this is not part of the language implementation, but the HTTP standard. You can find a better description in the HTTP method definitions here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

Claudiu Ceia

You can look at it as sending transparent data and data you want to hide. Transparent data (GET) could be options of the website, e.g.: a site you are visiting has 2 languages and you don't want to display it in default one. GET method is better here as you can bookmark the  site with this option and everytime you visit this site you don't have to switch language over and over On the other hand you don't want to show hidden data (POST) to someone else, e.g.: Logging data Personal preferences like what do you like and what you don't Personal messages

Michał Kardyś

As Claudiu points out, this is just HTTP standard, and you don't have to obey it.  You could totally store parameters in a POST url and parse it in the server side if you wish; it's just weird.

Derek Chiang

Like other people have said, the reason doesn't lie so much with the programming language you're using, as the way the HTTP specification is set up. When you first get into web programming, you may assume (as I did) that there are two types of HTTP requests, GET and POST. These are in fact just 2 of the verbs you can use, and if you start developing RESTful web apps, you'll start learning about the others. While the technical definition can be a pain to read through, think of it this way: a GET request is, no surprise, a request from your browser for the server to provide a specific resource. If I want to visit this Quora answer page, and you want to visit this Quora answer page, we should both be able to enter the same URL and retrieve the same content from the server. When I want to add to a resource (such as adding an answer to this question), I submit a POST request. Do I want to submit the exact same answer as someone else? No, I don't. Therefore, there shouldn't be a universal URL. There are other HTTP request types you can use (PUT, which creates a new resource, DELETE, and so on). If you develop in Rails, your app will automatically use them. PHP lets you do whatever the heck you want. Could you do everything with GET requests (i.e http://somesite.com/page.php?action=post)%3F Technically yes, but why do the extra work of adding additional unnecessary logic to your app when you can just use those sweet, sweet HTTP verbs?

Matt Muller

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.