Recover parameters with $_GET and $_POST in the same php file, is that correct?

Asked

Viewed 129 times

2

I make this request:

app js.:

fetch(URL + ?controller=UserController&action=insert,
                {
                    method: 'POST',
                    body: formData
                })

fetch php.:

 $controllerName = $_GET['controller'];
 $actionName = $_GET['action'];
 $nome = $_POST['nome']

To recover the data entered in the form, I use $_POST. To recover the parameter of url one $_GET. It is correct to use both in the same php file, and I am making a request via method "POST"?

  • 1

    Yes, because you are passing information via query string URL. As much as PHP calls $_GET, there is no direct relationship with the method GET of HTTP. In fact, the name (and existence) of these variables were an unhappiness in the development of language by inducing the developer to this relationship that does not exist.

  • Got it. So the methods have no direct relationship. Thanks for helping me.

1 answer

0

Francis,

In a simple way, verbs GET, POST, PUT, DELETE, PATCH and others represent a semantics suggested so that the systems become clearer. It is as each of them defined a clear action that is being requested from the system and this must be prepared for it. See more about Restful, it’s a good approach.

I believe that the standards suggested and adopted by many always have their value, so I suggest reading about Restful to have an information organization.

I am not an expert in PHP, but I believe that in this example he is receiving a POST and is treating the query_string with the $_GET, only a subtlety of language. Therefore, I see no problem, only a feature of language.

  • In the comment below my question, Woton Sampaio, explains that the methods have no direct relation, they are only names defined in php. So it’s right what I’m doing. Thank you for trying to help me.

  • Yes... truth... perfect the comment. I just tried to reinforce a little about the verbs, which at the present time, are important separations. A hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.