SecondCity Posted April 7, 2017 Share Posted April 7, 2017 What is a "GET request to a url"? I thought a GET request was when you gathered data from a url like this... www.bigandtall.net/index.php?name1=value1&name2=value2&name3=value3 Quote Link to comment Share on other sites More sharing options...
benanamen Posted April 7, 2017 Share Posted April 7, 2017 That is one way. Another is if you were to leave out the method= from a form. it will default to GET. There is also usage with cURL. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 7, 2017 Share Posted April 7, 2017 The HTTP protocol defines different request methods (GET, POST, PUT, DELETE, ...) with different semantics. GET requests are for obtaining a resource. This is what your browser does when you simply open a page or load an image. I thought a GET request was when you gathered data from a url like this... www.bigandtall.net/index.php?name1=value1&name2=value2&name3=value3 No. PHP happens to store URL parameters in a superglobal called $_GET, but this is poor terminology and probably has to do with the fact that when you choose the GET method in an HTML form, the data is sent via URL parameters (whereas POST uses the request body). But you can have URL parameters with any method, so the PHP names don't make much sense. What matters is the HTTP protocol. Quote Link to comment Share on other sites More sharing options...
SecondCity Posted April 7, 2017 Author Share Posted April 7, 2017 The HTTP protocol defines different request methods (GET, POST, PUT, DELETE, ...) with different semantics. GET requests are for obtaining a resource. This is what your browser does when you simply open a page or load an image. No. PHP happens to store URL parameters in a superglobal called $_GET, but this is poor terminology and probably has to do with the fact that when you choose the GET method in an HTML form, the data is sent via URL parameters (whereas POST uses the request body). But you can have URL parameters with any method, so the PHP names don't make much sense. What matters is the HTTP protocol. Not sure I followed you. What is the relationship between $_GET and $_POST and the URL and a web form? From what I know, I thought when you submit a PHP form it is usually a POST and the form values are stored in the $_POST variable. And when I think of GET, I think of when you are reading values in the URL like when someone searches for a product on an ecommerce site. So $_GET would store the data in the URL when you search for "big and tall" clothing. My questions relate to the fact that I am trying to learn cURL and I did some practice examples last night and one was using cURL's GET function to load a url (i.e. an entire website). This confused me, because I don't associate loading a website with a GET request. I think of GET as getting variable from the URL. Sfter writing all of this, I think I am more confused! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 7, 2017 Share Posted April 7, 2017 As I already said, forget about PHP for now. The superglobal names make no sense and won't help you understand the HTTP protocol. Do you know how HTTP works? A client makes a request to a server, and then the server sends a response. Pretty simple. Since the client can perform different actions, there are different “methods”: To load a resource (a page, an image, a video file, ...), you use the GET method. To update a resource, you use POST. To create a resource, you use PUT. To delete a resource you use DELETE. (In practice, POST is often used as a general purpose method for all data changes). For example, this is the request sent by my browser when I opened this page: GET /topic/303644-get-request-to-a-url/ Host: forums.phpfreaks.com (... and many other headers) Since I want to load the page, the GET method is being used. Got it? GET has nothing to do with URL parameters. It's just one particular HTTP method. Unfortunately, the PHP developers decided to confuse all web development newbies, so they came up with the stupid $_GET and $_POST superglobals. Once again: The names are poorly chosen. They don't make much sense. So if you don't understand the background, just accept the names as legacy baggage. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.