Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How $_POST works [closed]

Tags:

php

I am a beginner with PHP and I would really like to understand it a lot better. I know you can use $_POST to retrieve information from a form by setting method="$_POST". But why does this work exactly? Is, upon form submission, an array named $_POST created? Does the array then contain all of the element values from the form?

like image 901
Matthew Joseph Morris Avatar asked Mar 11 '26 23:03

Matthew Joseph Morris


1 Answers

When you press the submit button, your client will send a HTTP POST request to the script specified in action. In your situation, the values filled in the form will be sent as parameters in this request (note that a client can potentially send anything in a GET/POST request; this is important to know for security). PHP will put those parameters in the $_POST superglobal so the script can do something with the form data.

Forms aren't the only source of POST data, both in theory and in practice. For example, an API could accept HTTP POST requests, and Javascript can let a browser perform passive asynchronous requests using AJAX.

like image 129
Another Code Avatar answered Mar 14 '26 12:03

Another Code



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!