-2
In "execution blocks" I see a lot $_SESSION
for validation of forms and related, but did not understand very well what exactly means.
-2
In "execution blocks" I see a lot $_SESSION
for validation of forms and related, but did not understand very well what exactly means.
5
These are predefined variables, as stated in documentation. They are populated by the PHP virtual execution machine according to the execution context, so they are like exposed internal objects for your code to access.
It’s a simple and useful model, but if it were today I doubt that language would use something like this, since language is changing to be more Nterprise and less than script, where the context fit.
Specifically the $_SESSION
keeps a unique code indicating which session is active, so a script identify that his call is still part of an execution of the same session of some user and can thus give continuity to what he did in previous executions. The web is stateless, then it doesn’t save the situation between a call and another, its code has to deal with it, and a session identifier is the way to know which is the session, usually it is passed between the browser and the HTTP server by cookies.
Other cookies can be accessed by the variable $_COOKIE
. Data from the browser can be picked up by $_GET
, $_POST
, and $_FILES
to catch files being uploaded, or $_SERVER
for specific execution environment and call data; or $_ENV
for the general environment
$_REQUEST
is indifferent between the get and post, and can be used when no matter what form the request came in.
Among some others, even with slightly different standards, still has the $GLOBALS
to store values accessible by all script (which is usually very fast).
1
These variables are superglobal, and as the name says, their scope is global, meaning they can be accessed from anywhere in the code. Regarding the name starting with $_ has no purpose, it is just a default name for this type of variable.
PHP has the following superglobal variables:
-3
Whenever you find variables that start with $_ it means they are super global variables, that is, they are special variables that can be used in any part of your project, and each of them has a specific function.
For example $_SESSION['example'] creates a session, $_GET takes the values of the variables of the URL...etc...
Browser other questions tagged php global-variables
You are not signed in. Login or sign up in order to post.
Your question is about the global variable
$_SESSION
or about the prefix$_
?– gato
Well, in case you two
– Problemático
@Problematic Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero