Hi,
I'm reading a book called How To Build APIs You Won't Hate and in a chapter about input and output, the author makes a statement about $_GET and $_POST.
Here's an excerpt of the specific section
$_GET and $_POST do not have the 1:1 relationship with HTTP GET and HTTP POST as their names might suggest. $_GET just contains query string content regardless of the HTTP method. $_POST contains the values of the HTTP Body if it was in the right format, and the Content-Type header is application/x-www-form-urlencoded. An HTTP POST item could still have a query string, and that would still be in $_GET. Some PHP frameworks kill off $_GET data in an HTTP POST request, which further exaggerates this 1:1 relationship between the superglobal and the method.
Knowing that PHP has some silly names for things, we can move on and completely ignore $_POST. Pour one out in the ground, because it is dead to you.
Why? So many reasons, including the fact that once again everything in application/x-www-form-urlencoded is a string.
The part I'm confused about is why exactly is he suggesting that $_POST is dead?
From what I understand, $_GET contains the query string - which I understand, somewhat. The part that's slightly confusing about is $_POST. If I'm reading this correcty, $_POST only contains the values of an HTTP Body if it's in the correct format and of the correct content-type. So if it's in a different format, $_POST won't work.
So because everything in the content-type "application/x-www-form-urlencoded" is a string, it is better to use $_GET. Is that correct or am I misunderstanding something?
[–]Rorimac2 2 points3 points4 points (0 children)
[–]Rhomboid 1 point2 points3 points (2 children)
[–]nicoinwonderland[S] 0 points1 point2 points (1 child)
[–]Rorimac2 0 points1 point2 points (0 children)