Gibbs
Gibbs

Reputation: 22974

Why do we need a query string? and how it is exactly used in the backend to retrieve a page?

I really don't understand what is the actual purpose of a query string.

I can find

I can see links in SO also Use of Query params And I don't know why do wee need this? And how are they using this in the server side to retrieve datas.

Please let me know the use of this.

Note: I can understand we can pass form data through query strings. and Check against backend db to retrieve results.

But i don't understand how do they check page numbers and retrieve the results and some other query strings too.

I hope I am not asking too much and I just want a simple example in the backend processing of page numbers.

Thanks

Upvotes: 0

Views: 1440

Answers (2)

Jake Hargus
Jake Hargus

Reputation: 362

Query strings are just a way of passing information from page to server or page to page. It's not a concept just for web, you can use them for any kind of communication from a client to a web based server. An example is an iOS app that connects to a REST server. You might put the Device ID or name or client version number in a query string. When the server receives the call most servers will parse out the query string in a method call and add the values in a method call. Something like this:

https://www.server.com/iOSCall?deviceName=somename&deviceID=1234

could be parsed into a method structure like:

public void iOSCall(string deviceName, string deviceID)

then on the server you can use those variable names and values to do whatever, like logging which device made the call and return a response. A web page is the same way, you might put a data object's ID in the query string so the server knows what you're dealing with (those can be handled with post bodies for calls too, but query strings are easy and quick but not as secure).

So they're basically an easy way for clients to hand data off to servers, servers can handle that data and return a response.

Upvotes: 0

Ben Philipp
Ben Philipp

Reputation: 1877

The query string not only allows for data to be passed on to dynamic pages, but also it does it in such a way that the user can share the link, so that a different person would get the same page. This is what mainly seperates $_GET from $_POST. POST is more secure and "not in the way" as the user can't see it, but also when ever a page uses POST to retreive data, you can't link to that page in such a way that user B would have the page react in the same way as for the data you might have entered before.

Upvotes: 1

Related Questions