This is probably a simple question: how does PHP's $_POST
superglobal variable behave with PHP across multiple files within one session?
The manual on PHP.net states this: "This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script."
Here is my specific situation: I have one page that primarily contains HTML
with multiple forms - which are handled with jQuery. I then have an "intermediate" page that calls my PHP
class. Those two files continue the user's current session. Obviously, $_POST
is utilized extensively.
I am curious if $_POST
will "refresh" itself each time a form is submitted, or if it will add new identifiers in the array.
For instance,
Form Submission One => $_POST = $POST['firstname'], $POST['lastname']...
Form Submission Two => $_POST = $POST['firstname'], $POST['lastname']...+ $_POST['Id'], $_POST['whatever']...
Any input is appreciated.
$_POST
is populated from posted variables for that specific HTTP request. If you have multiple requests happening, then they will each have their own $_POST
.
Nothing is implicitly shared between requests. You must use session data for that.
The $_POST
variable is created for each query, based on the content inbound POSTed in the form. It will not persist between calls (that's $_SESSION
, and it behaves differently).
It's not that $_POST
refreshes on each form post, but rather that it is created uniquely for each HTTP POST transaction.